Skip to content

Commit eac6546

Browse files
authored
provider/digitalocean: Enforce Lowercase on IPV6 Addresses (hashicorp#7652)
IPV6 Addresses are generally case insensitive but it is recommented to store them as lowercase (https://tools.ietf.org/html/rfc5952#section-4.3) When Terraform didn't store them as LowerCase, we got the following error when using in DNS records: ``` -/+ digitalocean_record.web6 domain: "mydomain.com" => "mydomain.com" fqdn: "web02.in.mydomain.com" => "<computed>" name: "web02.in" => "web02.in" port: "0" => "<computed>" priority: "0" => "<computed>" type: "AAAA" => "AAAA" value: "2a03:b0c0:0003:00d0:0000:0000:0b66:6001" => "2A03:B0C0:0003:00D0:0000:0000:0B66:6001" (forces new resource) weight: "0" => "<computed>" ``` There was no need for this to be the case. We now enforce lowercase on both state and also when responses are returned from the API
1 parent 85c0105 commit eac6546

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

builtin/providers/digitalocean/resource_digitalocean_droplet.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ func resourceDigitalOceanDroplet() *schema.Resource {
7676
"ipv6_address": &schema.Schema{
7777
Type: schema.TypeString,
7878
Computed: true,
79+
StateFunc: func(val interface{}) string {
80+
return strings.ToLower(val.(string))
81+
},
7982
},
8083

8184
"ipv6_address_private": &schema.Schema{
@@ -253,7 +256,7 @@ func resourceDigitalOceanDropletRead(d *schema.ResourceData, meta interface{}) e
253256

254257
if publicIPv6 := findIPv6AddrByType(droplet, "public"); publicIPv6 != "" {
255258
d.Set("ipv6", true)
256-
d.Set("ipv6_address", publicIPv6)
259+
d.Set("ipv6_address", strings.ToLower(publicIPv6))
257260
d.Set("ipv6_address_private", findIPv6AddrByType(droplet, "private"))
258261
}
259262

builtin/providers/digitalocean/resource_digitalocean_droplet_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,16 @@ func testAccCheckDigitalOceanDropletAttributes_PrivateNetworkingIpv6(droplet *go
260260
return fmt.Errorf("No ipv6 public: %s", findIPv6AddrByType(droplet, "public"))
261261
}
262262

263+
for _, rs := range s.RootModule().Resources {
264+
if rs.Type != "digitalocean_droplet" {
265+
continue
266+
}
267+
if rs.Primary.Attributes["ipv6_address"] != strings.ToLower(findIPv6AddrByType(droplet, "public")) {
268+
return fmt.Errorf("IPV6 Address should be lowercase")
269+
}
270+
271+
}
272+
263273
return nil
264274
}
265275
}

0 commit comments

Comments
 (0)