Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix perpetual diff in #863. #1141

Merged
merged 2 commits into from
Mar 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion google/resource_dns_record_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import (
"fmt"
"log"

"strings"

"github.com/hashicorp/terraform/helper/schema"
"google.golang.org/api/dns/v1"
"strings"
)

func resourceDnsRecordSet() *schema.Resource {
Expand Down Expand Up @@ -38,6 +39,9 @@ func resourceDnsRecordSet() *schema.Resource {
Elem: &schema.Schema{
Type: schema.TypeString,
},
DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool {
return strings.ToLower(strings.Trim(old, `"`)) == strings.ToLower(strings.Trim(new, `"`))
},
},

"ttl": &schema.Schema{
Expand Down
104 changes: 92 additions & 12 deletions google/resource_dns_record_set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,46 @@ func TestAccDnsRecordSet_nestedNS(t *testing.T) {
})
}

func TestAccDnsRecordSet_quotedTXT(t *testing.T) {
t.Parallel()

zoneName := fmt.Sprintf("dnszone-test-txt-%s", acctest.RandString(10))
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckDnsRecordSetDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccDnsRecordSet_quotedTXT(zoneName, 300),
Check: resource.ComposeTestCheckFunc(
testAccCheckDnsRecordSetExists(
"google_dns_record_set.foobar", zoneName),
),
},
},
})
}

func TestAccDnsRecordSet_uppercaseMX(t *testing.T) {
t.Parallel()

zoneName := fmt.Sprintf("dnszone-test-txt-%s", acctest.RandString(10))
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckDnsRecordSetDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccDnsRecordSet_uppercaseMX(zoneName, 300),
Check: resource.ComposeTestCheckFunc(
testAccCheckDnsRecordSetExists(
"google_dns_record_set.foobar", zoneName),
),
},
},
})
}

func testAccCheckDnsRecordSetDestroy(s *terraform.State) error {
config := testAccProvider.Meta().(*Config)

Expand Down Expand Up @@ -196,66 +236,106 @@ func testAccDnsRecordSet_basic(zoneName string, addr2 string, ttl int) string {
return fmt.Sprintf(`
resource "google_dns_managed_zone" "parent-zone" {
name = "%s"
dns_name = "hashicorptest.com."
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.hashicorptest.com."
name = "test-record.%s.hashicorptest.com."
type = "A"
rrdatas = ["127.0.0.1", "%s"]
ttl = %d
}
`, zoneName, addr2, ttl)
`, zoneName, zoneName, zoneName, addr2, ttl)
}

func testAccDnsRecordSet_ns(name string, ttl int) string {
return fmt.Sprintf(`
resource "google_dns_managed_zone" "parent-zone" {
name = "%s"
dns_name = "hashicorptest.com."
dns_name = "%s.hashicorptest.com."
description = "Test Description"
}
resource "google_dns_record_set" "foobar" {
managed_zone = "${google_dns_managed_zone.parent-zone.name}"
name = "hashicorptest.com."
name = "%s.hashicorptest.com."
type = "NS"
rrdatas = ["ns.hashicorp.services.", "ns2.hashicorp.services."]
ttl = %d
}
`, name, ttl)
`, name, name, name, ttl)
}

func testAccDnsRecordSet_nestedNS(name string, ttl int) string {
return fmt.Sprintf(`
resource "google_dns_managed_zone" "parent-zone" {
name = "%s"
dns_name = "hashicorptest.com."
dns_name = "%s.hashicorptest.com."
description = "Test Description"
}
resource "google_dns_record_set" "foobar" {
managed_zone = "${google_dns_managed_zone.parent-zone.name}"
name = "nested.hashicorptest.com."
name = "nested.%s.hashicorptest.com."
type = "NS"
rrdatas = ["ns.hashicorp.services.", "ns2.hashicorp.services."]
ttl = %d
}
`, name, ttl)
`, name, name, name, ttl)
}

func testAccDnsRecordSet_bigChange(zoneName string, ttl int) string {
return fmt.Sprintf(`
resource "google_dns_managed_zone" "parent-zone" {
name = "%s"
dns_name = "hashicorptest.com."
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.hashicorptest.com."
name = "test-record.%s.hashicorptest.com."
type = "CNAME"
rrdatas = ["www.terraform.io."]
ttl = %d
}
`, zoneName, ttl)
`, zoneName, zoneName, zoneName, ttl)
}

func testAccDnsRecordSet_quotedTXT(name string, ttl int) 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 = ["test", "\"quoted test\""]
ttl = %d
}
`, name, name, name, ttl)
}

func testAccDnsRecordSet_uppercaseMX(name string, ttl int) 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 = "MX"
rrdatas = [
"1 ASPMX.L.GOOGLE.COM.",
"5 ALT1.ASPMX.L.GOOGLE.COM.",
"5 ALT2.ASPMX.L.GOOGLE.COM.",
"10 ASPMX2.GOOGLEMAIL.COM.",
"10 ASPMX3.GOOGLEMAIL.COM.",
]
ttl = %d
}
`, name, name, name, ttl)
}