Skip to content

Commit 4e8ad95

Browse files
Local IP Range support in compute_firewall (#6931) (#13240)
Signed-off-by: Modular Magician <[email protected]> Signed-off-by: Modular Magician <[email protected]>
1 parent 7bbe743 commit 4e8ad95

File tree

3 files changed

+91
-5
lines changed

3 files changed

+91
-5
lines changed

.changelog/6931.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
compute: Add support for Local IP Ranges in `google_compute_firewall`
3+
```

google/resource_compute_firewall.go

+3-5
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,7 @@ must be expressed in CIDR format. Only IPv4 is supported.`,
213213
Elem: &schema.Schema{
214214
Type: schema.TypeString,
215215
},
216-
Set: schema.HashString,
217-
ConflictsWith: []string{"source_ranges", "source_tags"},
216+
Set: schema.HashString,
218217
},
219218
"direction": {
220219
Type: schema.TypeString,
@@ -282,8 +281,7 @@ apply. Only IPv4 is supported. For INGRESS traffic, one of 'source_ranges',
282281
Elem: &schema.Schema{
283282
Type: schema.TypeString,
284283
},
285-
Set: schema.HashString,
286-
ConflictsWith: []string{"destination_ranges"},
284+
Set: schema.HashString,
287285
},
288286
"source_service_accounts": {
289287
Type: schema.TypeSet,
@@ -324,7 +322,7 @@ one of 'source_ranges', 'source_tags' or 'source_service_accounts' is required.`
324322
Type: schema.TypeString,
325323
},
326324
Set: schema.HashString,
327-
ConflictsWith: []string{"source_service_accounts", "destination_ranges", "target_service_accounts"},
325+
ConflictsWith: []string{"source_service_accounts", "target_service_accounts"},
328326
},
329327
"target_service_accounts": {
330328
Type: schema.TypeSet,

google/resource_compute_firewall_test.go

+85
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,45 @@ func TestAccComputeFirewall_update(t *testing.T) {
4747
})
4848
}
4949

50+
func TestAccComputeFirewall_localRanges(t *testing.T) {
51+
t.Parallel()
52+
53+
networkName := fmt.Sprintf("tf-test-firewall-%s", randString(t, 10))
54+
firewallName := fmt.Sprintf("tf-test-firewall-%s", randString(t, 10))
55+
56+
vcrTest(t, resource.TestCase{
57+
PreCheck: func() { testAccPreCheck(t) },
58+
Providers: testAccProviders,
59+
CheckDestroy: testAccCheckComputeFirewallDestroyProducer(t),
60+
Steps: []resource.TestStep{
61+
{
62+
Config: testAccComputeFirewall_localRanges(networkName, firewallName),
63+
},
64+
{
65+
ResourceName: "google_compute_firewall.foobar",
66+
ImportState: true,
67+
ImportStateVerify: true,
68+
},
69+
{
70+
Config: testAccComputeFirewall_localRangesUpdate(networkName, firewallName),
71+
},
72+
{
73+
ResourceName: "google_compute_firewall.foobar",
74+
ImportState: true,
75+
ImportStateVerify: true,
76+
},
77+
{
78+
Config: testAccComputeFirewall_localRanges(networkName, firewallName),
79+
},
80+
{
81+
ResourceName: "google_compute_firewall.foobar",
82+
ImportState: true,
83+
ImportStateVerify: true,
84+
},
85+
},
86+
})
87+
}
88+
5089
func TestAccComputeFirewall_priority(t *testing.T) {
5190
t.Parallel()
5291

@@ -282,6 +321,52 @@ resource "google_compute_firewall" "foobar" {
282321
`, network, firewall)
283322
}
284323

324+
func testAccComputeFirewall_localRanges(network, firewall string) string {
325+
return fmt.Sprintf(`
326+
resource "google_compute_network" "foobar" {
327+
name = "%s"
328+
auto_create_subnetworks = false
329+
}
330+
331+
resource "google_compute_firewall" "foobar" {
332+
name = "%s"
333+
description = "Resource created for Terraform acceptance testing"
334+
network = google_compute_network.foobar.name
335+
source_tags = ["foo"]
336+
337+
source_ranges = ["10.0.0.0/8"]
338+
destination_ranges = ["192.168.1.0/24"]
339+
340+
allow {
341+
protocol = "icmp"
342+
}
343+
}
344+
`, network, firewall)
345+
}
346+
347+
func testAccComputeFirewall_localRangesUpdate(network, firewall string) string {
348+
return fmt.Sprintf(`
349+
resource "google_compute_network" "foobar" {
350+
name = "%s"
351+
auto_create_subnetworks = false
352+
}
353+
354+
resource "google_compute_firewall" "foobar" {
355+
name = "%s"
356+
description = "Resource created for Terraform acceptance testing"
357+
network = google_compute_network.foobar.name
358+
source_tags = ["foo"]
359+
360+
source_ranges = ["192.168.1.0/24"]
361+
destination_ranges = ["10.0.0.0/8"]
362+
363+
allow {
364+
protocol = "icmp"
365+
}
366+
}
367+
`, network, firewall)
368+
}
369+
285370
func testAccComputeFirewall_update(network, firewall string) string {
286371
return fmt.Sprintf(`
287372
resource "google_compute_network" "foobar" {

0 commit comments

Comments
 (0)