Skip to content

Commit

Permalink
Check empty string for new resource creation (#6313) (#4515)
Browse files Browse the repository at this point in the history
* Check empty string for new resource creation

* Add test

Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored Jul 21, 2022
1 parent 17e4cb6 commit dbc4928
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .changelog/6313.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
dns: fixed a bug where `google_dns_record_set` would create an inconsistent plan when using interpolated values in `rrdatas`
```
2 changes: 1 addition & 1 deletion google-beta/resource_dns_record_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
)

func rrdatasDnsDiffSuppress(k, old, new string, d *schema.ResourceData) bool {
if k == "rrdatas.#" && new == "0" && old != new {
if k == "rrdatas.#" && (new == "0" || new == "") && old != new {
return false
}

Expand Down
41 changes: 41 additions & 0 deletions google-beta/resource_dns_record_set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,29 @@ func TestAccDNSRecordSet_changeRouting(t *testing.T) {
})
}

// Tracks fix for https://github.com/hashicorp/terraform-provider-google/issues/12043
func TestAccDNSRecordSet_interpolated(t *testing.T) {
t.Parallel()

zoneName := fmt.Sprintf("dnszone-test-%s", randString(t, 10))
vcrTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckDnsRecordSetDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccDnsRecordSet_interpolated(zoneName),
},
{
ResourceName: "google_dns_record_set.foobar",
ImportStateId: fmt.Sprintf("%s/test-record.%s.hashicorptest.com./TXT", zoneName, zoneName),
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func testAccCheckDnsRecordSetDestroyProducer(t *testing.T) func(s *terraform.State) error {

return func(s *terraform.State) error {
Expand Down Expand Up @@ -491,3 +514,21 @@ resource "google_dns_record_set" "foobar" {
}
`, zoneName, zoneName, zoneName, ttl, location, addr2)
}

func testAccDnsRecordSet_interpolated(zoneName string) string {
return fmt.Sprintf(`
resource "google_dns_managed_zone" "parent-zone" {
name = "%s"
dns_name = "%s.hashicorptest.com."
description = "Test Description"
}
resource "google_dns_record_set" "foobar" {
managed_zone = google_dns_managed_zone.parent-zone.name
name = "test-record.%s.hashicorptest.com."
type = "TXT"
rrdatas = ["127.0.0.1", "firebase=${google_dns_managed_zone.parent-zone.id}"]
ttl = 10
}
`, zoneName, zoneName, zoneName)
}

0 comments on commit dbc4928

Please sign in to comment.