mirror of
https://github.com/letic/terraform-provider-google.git
synced 2024-10-01 16:21:06 +00:00
Add a DiffSupress for ipv6 shortening (#1551)
This commit is contained in:
parent
a598390697
commit
e4c9b2d4b1
@ -8,6 +8,7 @@ import (
|
||||
|
||||
"github.com/hashicorp/terraform/helper/schema"
|
||||
"google.golang.org/api/dns/v1"
|
||||
"net"
|
||||
)
|
||||
|
||||
func resourceDnsRecordSet() *schema.Resource {
|
||||
@ -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, `"`))
|
||||
@ -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)
|
||||
}
|
||||
|
@ -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()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user