Skip to content

Commit 45692c1

Browse files
Upstream firewalls DSF update to allow unknown values coming from interpolation (#5526) (#10976)
Signed-off-by: Modular Magician <[email protected]>
1 parent 3c40b7d commit 45692c1

File tree

3 files changed

+65
-2
lines changed

3 files changed

+65
-2
lines changed

.changelog/5526.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:bug
2+
compute: fixed a bug where `google_compute_firewall` would incorrectly find `source_ranges` to be empty during validation
3+
```

google/resource_compute_firewall.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,10 @@ func resourceComputeFirewallSourceFieldsCustomizeDiff(_ context.Context, diff *s
8787
_, sasOk := diff.GetOk("source_service_accounts")
8888

8989
_, tagsExist := diff.GetOkExists("source_tags")
90-
// ranges is computed, but this is what we're trying to avoid, so we're not going to check this
90+
_, rangesExist := diff.GetOkExists("source_ranges")
9191
_, sasExist := diff.GetOkExists("source_service_accounts")
9292

93-
if !tagsOk && !rangesOk && !sasOk && !tagsExist && !sasExist {
93+
if !tagsOk && !rangesOk && !sasOk && !tagsExist && !rangesExist && !sasExist {
9494
return fmt.Errorf("one of source_tags, source_ranges, or source_service_accounts must be defined")
9595
}
9696
}

google/resource_compute_firewall_test.go

+60
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,29 @@ func TestAccComputeFirewall_enableLogging(t *testing.T) {
239239
})
240240
}
241241

242+
func TestAccComputeFirewall_moduleOutput(t *testing.T) {
243+
t.Parallel()
244+
245+
networkName := fmt.Sprintf("tf-test-firewall-%s", randString(t, 10))
246+
firewallName := fmt.Sprintf("tf-test-firewall-%s", randString(t, 10))
247+
248+
vcrTest(t, resource.TestCase{
249+
PreCheck: func() { testAccPreCheck(t) },
250+
Providers: testAccProviders,
251+
CheckDestroy: testAccCheckComputeFirewallDestroyProducer(t),
252+
Steps: []resource.TestStep{
253+
{
254+
Config: testAccComputeFirewall_moduleOutput(networkName, firewallName),
255+
},
256+
{
257+
ResourceName: "google_compute_firewall.foobar",
258+
ImportState: true,
259+
ImportStateVerify: true,
260+
},
261+
},
262+
})
263+
}
264+
242265
func testAccComputeFirewall_basic(network, firewall string) string {
243266
return fmt.Sprintf(`
244267
resource "google_compute_network" "foobar" {
@@ -444,3 +467,40 @@ resource "google_compute_firewall" "foobar" {
444467
}
445468
`, network, firewall, enableLoggingCfg)
446469
}
470+
471+
func testAccComputeFirewall_moduleOutput(network, firewall string) string {
472+
return fmt.Sprintf(`
473+
resource "google_compute_network" "foobar" {
474+
name = "%s"
475+
auto_create_subnetworks = false
476+
}
477+
478+
resource "google_compute_subnetwork" "foobar" {
479+
name = "%s-subnet"
480+
ip_cidr_range = "10.0.0.0/16"
481+
region = "us-central1"
482+
network = google_compute_network.foobar.name
483+
}
484+
485+
resource "google_compute_address" "foobar" {
486+
name = "%s-address"
487+
subnetwork = google_compute_subnetwork.foobar.id
488+
address_type = "INTERNAL"
489+
region = "us-central1"
490+
}
491+
492+
resource "google_compute_firewall" "foobar" {
493+
name = "%s"
494+
description = "Resource created for Terraform acceptance testing"
495+
network = google_compute_network.foobar.name
496+
direction = "INGRESS"
497+
498+
source_ranges = ["${google_compute_address.foobar.address}/32"]
499+
target_tags = ["foo"]
500+
501+
allow {
502+
protocol = "tcp"
503+
}
504+
}
505+
`, network, network, network, firewall)
506+
}

0 commit comments

Comments
 (0)