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" {