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

Suppress diff for ipv6 shortening in dns record #1551

Merged
merged 1 commit into from
May 29, 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
14 changes: 14 additions & 0 deletions google/resource_dns_record_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

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

func resourceDnsRecordSet() *schema.Resource {
Expand Down Expand Up @@ -38,6 +39,12 @@ func resourceDnsRecordSet() *schema.Resource {
Required: true,
Elem: &schema.Schema{
Type: schema.TypeString,
DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool {
if d.Get("type") == "AAAA" {
return ipv6AddressDiffSuppress(k, old, new, d)
}
return false
},
},
DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool {
return strings.ToLower(strings.Trim(old, `"`)) == strings.ToLower(strings.Trim(new, `"`))
Expand Down Expand Up @@ -320,3 +327,10 @@ func rrdata(
}
return data
}

func ipv6AddressDiffSuppress(_, old, new string, _ *schema.ResourceData) bool {
oldIp := net.ParseIP(old)
newIp := net.ParseIP(new)

return oldIp.Equal(newIp)
}
25 changes: 25 additions & 0 deletions google/resource_dns_record_set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,31 @@ import (
"github.com/hashicorp/terraform/terraform"
)

func TestIpv6AddressDiffSuppress(t *testing.T) {
cases := map[string]struct {
Old, New string
ShouldSuppress bool
}{
"compact form should suppress diff": {
Old: "2a03:b0c0:1:e0::29b:8001",
New: "2a03:b0c0:0001:00e0:0000:0000:029b:8001",
ShouldSuppress: true,
},
"different address should not suppress diff": {
Old: "2a03:b0c0:1:e00::29b:8001",
New: "2a03:b0c0:0001:00e0:0000:0000:029b:8001",
ShouldSuppress: false,
},
}

for tn, tc := range cases {
shouldSuppress := ipv6AddressDiffSuppress("", tc.Old, tc.New, nil)
if shouldSuppress != tc.ShouldSuppress {
t.Errorf("%s: expected %t", tn, tc.ShouldSuppress)
}
}
}

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

Expand Down