From 17799ee07f13adb2b1260ba31bc94c4025f7bb57 Mon Sep 17 00:00:00 2001 From: The Magician Date: Tue, 18 Jun 2024 11:44:06 -0700 Subject: [PATCH] Fix firewall rule to support empty descritpion on update (#10950) (#7563) [upstream:68ea8612247a46f4aac90e5b17eb7ecd6cb891b3] Signed-off-by: Modular Magician --- .changelog/10950.txt | 3 ++ .../compute/resource_compute_firewall.go | 4 +-- .../compute/resource_compute_firewall_test.go | 33 +++++++++++++++++++ 3 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 .changelog/10950.txt diff --git a/.changelog/10950.txt b/.changelog/10950.txt new file mode 100644 index 0000000000..208a085c2d --- /dev/null +++ b/.changelog/10950.txt @@ -0,0 +1,3 @@ +```release-note:bug +compute: fixed `description` field in `google_compute_firewall` to support empty/null values on update +``` \ No newline at end of file diff --git a/google-beta/services/compute/resource_compute_firewall.go b/google-beta/services/compute/resource_compute_firewall.go index 3769f21d68..c851d5f2a1 100644 --- a/google-beta/services/compute/resource_compute_firewall.go +++ b/google-beta/services/compute/resource_compute_firewall.go @@ -466,7 +466,7 @@ func resourceComputeFirewallCreate(d *schema.ResourceData, meta interface{}) err descriptionProp, err := expandComputeFirewallDescription(d.Get("description"), d, config) if err != nil { return err - } else if v, ok := d.GetOkExists("description"); !tpgresource.IsEmptyValue(reflect.ValueOf(descriptionProp)) && (ok || !reflect.DeepEqual(v, descriptionProp)) { + } else if v, ok := d.GetOkExists("description"); ok || !reflect.DeepEqual(v, descriptionProp) { obj["description"] = descriptionProp } destinationRangesProp, err := expandComputeFirewallDestinationRanges(d.Get("destination_ranges"), d, config) @@ -726,7 +726,7 @@ func resourceComputeFirewallUpdate(d *schema.ResourceData, meta interface{}) err descriptionProp, err := expandComputeFirewallDescription(d.Get("description"), d, config) if err != nil { return err - } else if v, ok := d.GetOkExists("description"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, descriptionProp)) { + } else if v, ok := d.GetOkExists("description"); ok || !reflect.DeepEqual(v, descriptionProp) { obj["description"] = descriptionProp } destinationRangesProp, err := expandComputeFirewallDestinationRanges(d.Get("destination_ranges"), d, config) diff --git a/google-beta/services/compute/resource_compute_firewall_test.go b/google-beta/services/compute/resource_compute_firewall_test.go index 5796a78d99..ac41df08bb 100644 --- a/google-beta/services/compute/resource_compute_firewall_test.go +++ b/google-beta/services/compute/resource_compute_firewall_test.go @@ -38,6 +38,17 @@ func TestAccComputeFirewall_update(t *testing.T) { ImportState: true, ImportStateVerify: true, }, + { + Config: testAccComputeFirewall_nullDescription(networkName, firewallName), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("google_compute_firewall.foobar", "description", ""), + ), + }, + { + ResourceName: "google_compute_firewall.foobar", + ImportState: true, + ImportStateVerify: true, + }, { Config: testAccComputeFirewall_basic(networkName, firewallName), }, @@ -392,6 +403,28 @@ resource "google_compute_firewall" "foobar" { `, network, firewall) } +func testAccComputeFirewall_nullDescription(network, firewall string) string { + return fmt.Sprintf(` +resource "google_compute_network" "foobar" { + name = "%s" + auto_create_subnetworks = false +} + +resource "google_compute_firewall" "foobar" { + name = "%s" + description = null + network = google_compute_network.foobar.self_link + source_tags = ["foo"] + target_tags = ["bar"] + + allow { + protocol = "tcp" + ports = ["80-255"] + } +} +`, network, firewall) +} + func testAccComputeFirewall_priority(network, firewall string, priority int) string { return fmt.Sprintf(` resource "google_compute_network" "foobar" {