Skip to content

Commit

Permalink
Fix firewall rule to support empty descritpion on update (#10950) (#1…
Browse files Browse the repository at this point in the history
…8478)

[upstream:68ea8612247a46f4aac90e5b17eb7ecd6cb891b3]

Signed-off-by: Modular Magician <magic-modules@google.com>
  • Loading branch information
modular-magician authored Jun 18, 2024
1 parent a4438d4 commit 5508d74
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .changelog/10950.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
compute: fixed `description` field in `google_compute_firewall` to support empty/null values on update
```
4 changes: 2 additions & 2 deletions google/services/compute/resource_compute_firewall.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
33 changes: 33 additions & 0 deletions google/services/compute/resource_compute_firewall_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
},
Expand Down Expand Up @@ -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" {
Expand Down

0 comments on commit 5508d74

Please sign in to comment.