Skip to content

Commit 17799ee

Browse files
Fix firewall rule to support empty descritpion on update (#10950) (#7563)
[upstream:68ea8612247a46f4aac90e5b17eb7ecd6cb891b3] Signed-off-by: Modular Magician <[email protected]>
1 parent ce5db1c commit 17799ee

File tree

3 files changed

+38
-2
lines changed

3 files changed

+38
-2
lines changed

.changelog/10950.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:bug
2+
compute: fixed `description` field in `google_compute_firewall` to support empty/null values on update
3+
```

google-beta/services/compute/resource_compute_firewall.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ func resourceComputeFirewallCreate(d *schema.ResourceData, meta interface{}) err
466466
descriptionProp, err := expandComputeFirewallDescription(d.Get("description"), d, config)
467467
if err != nil {
468468
return err
469-
} else if v, ok := d.GetOkExists("description"); !tpgresource.IsEmptyValue(reflect.ValueOf(descriptionProp)) && (ok || !reflect.DeepEqual(v, descriptionProp)) {
469+
} else if v, ok := d.GetOkExists("description"); ok || !reflect.DeepEqual(v, descriptionProp) {
470470
obj["description"] = descriptionProp
471471
}
472472
destinationRangesProp, err := expandComputeFirewallDestinationRanges(d.Get("destination_ranges"), d, config)
@@ -726,7 +726,7 @@ func resourceComputeFirewallUpdate(d *schema.ResourceData, meta interface{}) err
726726
descriptionProp, err := expandComputeFirewallDescription(d.Get("description"), d, config)
727727
if err != nil {
728728
return err
729-
} else if v, ok := d.GetOkExists("description"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, descriptionProp)) {
729+
} else if v, ok := d.GetOkExists("description"); ok || !reflect.DeepEqual(v, descriptionProp) {
730730
obj["description"] = descriptionProp
731731
}
732732
destinationRangesProp, err := expandComputeFirewallDestinationRanges(d.Get("destination_ranges"), d, config)

google-beta/services/compute/resource_compute_firewall_test.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,17 @@ func TestAccComputeFirewall_update(t *testing.T) {
3838
ImportState: true,
3939
ImportStateVerify: true,
4040
},
41+
{
42+
Config: testAccComputeFirewall_nullDescription(networkName, firewallName),
43+
Check: resource.ComposeTestCheckFunc(
44+
resource.TestCheckResourceAttr("google_compute_firewall.foobar", "description", ""),
45+
),
46+
},
47+
{
48+
ResourceName: "google_compute_firewall.foobar",
49+
ImportState: true,
50+
ImportStateVerify: true,
51+
},
4152
{
4253
Config: testAccComputeFirewall_basic(networkName, firewallName),
4354
},
@@ -392,6 +403,28 @@ resource "google_compute_firewall" "foobar" {
392403
`, network, firewall)
393404
}
394405

406+
func testAccComputeFirewall_nullDescription(network, firewall string) string {
407+
return fmt.Sprintf(`
408+
resource "google_compute_network" "foobar" {
409+
name = "%s"
410+
auto_create_subnetworks = false
411+
}
412+
413+
resource "google_compute_firewall" "foobar" {
414+
name = "%s"
415+
description = null
416+
network = google_compute_network.foobar.self_link
417+
source_tags = ["foo"]
418+
target_tags = ["bar"]
419+
420+
allow {
421+
protocol = "tcp"
422+
ports = ["80-255"]
423+
}
424+
}
425+
`, network, firewall)
426+
}
427+
395428
func testAccComputeFirewall_priority(network, firewall string, priority int) string {
396429
return fmt.Sprintf(`
397430
resource "google_compute_network" "foobar" {

0 commit comments

Comments
 (0)