From eac6546e33c30034e5507ddc21747459eaa62003 Mon Sep 17 00:00:00 2001 From: Paul Stack Date: Mon, 15 Aug 2016 15:52:48 +0100 Subject: [PATCH] provider/digitalocean: Enforce Lowercase on IPV6 Addresses (#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" => "" name: "web02.in" => "web02.in" port: "0" => "" priority: "0" => "" 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" => "" ``` 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 --- .../digitalocean/resource_digitalocean_droplet.go | 5 ++++- .../digitalocean/resource_digitalocean_droplet_test.go | 10 ++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/builtin/providers/digitalocean/resource_digitalocean_droplet.go b/builtin/providers/digitalocean/resource_digitalocean_droplet.go index a44f3eb3a2..a33e20d881 100644 --- a/builtin/providers/digitalocean/resource_digitalocean_droplet.go +++ b/builtin/providers/digitalocean/resource_digitalocean_droplet.go @@ -76,6 +76,9 @@ func resourceDigitalOceanDroplet() *schema.Resource { "ipv6_address": &schema.Schema{ Type: schema.TypeString, Computed: true, + StateFunc: func(val interface{}) string { + return strings.ToLower(val.(string)) + }, }, "ipv6_address_private": &schema.Schema{ @@ -253,7 +256,7 @@ func resourceDigitalOceanDropletRead(d *schema.ResourceData, meta interface{}) e if publicIPv6 := findIPv6AddrByType(droplet, "public"); publicIPv6 != "" { d.Set("ipv6", true) - d.Set("ipv6_address", publicIPv6) + d.Set("ipv6_address", strings.ToLower(publicIPv6)) d.Set("ipv6_address_private", findIPv6AddrByType(droplet, "private")) } diff --git a/builtin/providers/digitalocean/resource_digitalocean_droplet_test.go b/builtin/providers/digitalocean/resource_digitalocean_droplet_test.go index d6f2b190d3..9ac1473c1a 100644 --- a/builtin/providers/digitalocean/resource_digitalocean_droplet_test.go +++ b/builtin/providers/digitalocean/resource_digitalocean_droplet_test.go @@ -260,6 +260,16 @@ func testAccCheckDigitalOceanDropletAttributes_PrivateNetworkingIpv6(droplet *go return fmt.Errorf("No ipv6 public: %s", findIPv6AddrByType(droplet, "public")) } + for _, rs := range s.RootModule().Resources { + if rs.Type != "digitalocean_droplet" { + continue + } + if rs.Primary.Attributes["ipv6_address"] != strings.ToLower(findIPv6AddrByType(droplet, "public")) { + return fmt.Errorf("IPV6 Address should be lowercase") + } + + } + return nil } }