From 5d8c753eb90f8f6f46ddb8f44a994e3dc76d9b08 Mon Sep 17 00:00:00 2001 From: Stephen Hoekstra Date: Sun, 19 Apr 2020 23:49:05 +0200 Subject: [PATCH] Store offering type as case insensitive value A bug exists where terraform tries to update a resource's offering type if the case supplied by user does not match what's in the state. This causes an error from the Cosmic API as it returns a message that the offering type is already set. This was found in the instance offering but the fix has been extended to other resources with an offering field. Signed-off-by: Stephen Hoekstra --- CHANGELOG.md | 1 + cosmic/resource_cosmic_disk.go | 3 +++ cosmic/resource_cosmic_disk_test.go | 3 ++- cosmic/resource_cosmic_instance.go | 3 +++ cosmic/resource_cosmic_instance_test.go | 3 ++- cosmic/resource_cosmic_network.go | 3 +++ cosmic/resource_cosmic_network_test.go | 3 ++- cosmic/resource_cosmic_vpc.go | 3 +++ cosmic/resource_cosmic_vpc_test.go | 3 ++- 9 files changed, 21 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f0165f3..4626b70 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p - Add ability to rename `cosmic_network_acl`'s `name` and `description` fields - Add `client_timeout` and `server_timeout` fields to `cosmic_loadbalancer_rule` +- Fix bug where a resource's offering is saved in state as a case sensitive value - Fix bug where changing `cosmic_loadbalancer_rule` private or public ports did not recreate the resource - Fix bug where changing `cosmic_loadbalancer_rule` protocol did not recreate the resource diff --git a/cosmic/resource_cosmic_disk.go b/cosmic/resource_cosmic_disk.go index 35f962b..4ddd69e 100644 --- a/cosmic/resource_cosmic_disk.go +++ b/cosmic/resource_cosmic_disk.go @@ -28,6 +28,9 @@ func resourceCosmicDisk() *schema.Resource { "disk_offering": &schema.Schema{ Type: schema.TypeString, Required: true, + DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool { + return strings.EqualFold(old, new) + }, }, "attach": &schema.Schema{ diff --git a/cosmic/resource_cosmic_disk_test.go b/cosmic/resource_cosmic_disk_test.go index 69b608d..f50338e 100644 --- a/cosmic/resource_cosmic_disk_test.go +++ b/cosmic/resource_cosmic_disk_test.go @@ -2,6 +2,7 @@ package cosmic import ( "fmt" + "strings" "testing" "github.com/MissionCriticalCloud/go-cosmic/v6/cosmic" @@ -344,7 +345,7 @@ resource "cosmic_disk" "foo" { disk_offering = "%s" zone = "%s" }`, - COSMIC_DISK_OFFERING, + strings.ToLower(COSMIC_DISK_OFFERING), COSMIC_ZONE, ) diff --git a/cosmic/resource_cosmic_instance.go b/cosmic/resource_cosmic_instance.go index c1780e6..b2a48aa 100644 --- a/cosmic/resource_cosmic_instance.go +++ b/cosmic/resource_cosmic_instance.go @@ -38,6 +38,9 @@ func resourceCosmicInstance() *schema.Resource { "service_offering": { Type: schema.TypeString, Required: true, + DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool { + return strings.EqualFold(old, new) + }, }, "network_id": { diff --git a/cosmic/resource_cosmic_instance_test.go b/cosmic/resource_cosmic_instance_test.go index 7852f2f..20eb816 100644 --- a/cosmic/resource_cosmic_instance_test.go +++ b/cosmic/resource_cosmic_instance_test.go @@ -2,6 +2,7 @@ package cosmic import ( "fmt" + "strings" "testing" "github.com/MissionCriticalCloud/go-cosmic/v6/cosmic" @@ -388,7 +389,7 @@ resource "cosmic_instance" "foo" { COSMIC_VPC_OFFERING, COSMIC_ZONE, COSMIC_VPC_NETWORK_OFFERING, - COSMIC_SERVICE_OFFERING_1, + strings.ToLower(COSMIC_SERVICE_OFFERING_1), COSMIC_TEMPLATE, ) diff --git a/cosmic/resource_cosmic_network.go b/cosmic/resource_cosmic_network.go index 463b849..dc5a8cb 100644 --- a/cosmic/resource_cosmic_network.go +++ b/cosmic/resource_cosmic_network.go @@ -97,6 +97,9 @@ func resourceCosmicNetwork() *schema.Resource { "network_offering": &schema.Schema{ Type: schema.TypeString, Required: true, + DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool { + return strings.EqualFold(old, new) + }, }, "vlan": &schema.Schema{ diff --git a/cosmic/resource_cosmic_network_test.go b/cosmic/resource_cosmic_network_test.go index a67ab62..11b1b87 100644 --- a/cosmic/resource_cosmic_network_test.go +++ b/cosmic/resource_cosmic_network_test.go @@ -2,6 +2,7 @@ package cosmic import ( "fmt" + "strings" "testing" "github.com/MissionCriticalCloud/go-cosmic/v6/cosmic" @@ -263,7 +264,7 @@ resource "cosmic_network" "foo" { terraform-tag = "true" } }`, - COSMIC_VPC_OFFERING, + strings.ToLower(COSMIC_VPC_OFFERING), COSMIC_ZONE, COSMIC_VPC_NETWORK_OFFERING, ) diff --git a/cosmic/resource_cosmic_vpc.go b/cosmic/resource_cosmic_vpc.go index 89c3fab..3fc1f12 100644 --- a/cosmic/resource_cosmic_vpc.go +++ b/cosmic/resource_cosmic_vpc.go @@ -40,6 +40,9 @@ func resourceCosmicVPC() *schema.Resource { "vpc_offering": &schema.Schema{ Type: schema.TypeString, Required: true, + DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool { + return strings.EqualFold(old, new) + }, }, "network_domain": &schema.Schema{ diff --git a/cosmic/resource_cosmic_vpc_test.go b/cosmic/resource_cosmic_vpc_test.go index bd8c48e..f5ac57f 100644 --- a/cosmic/resource_cosmic_vpc_test.go +++ b/cosmic/resource_cosmic_vpc_test.go @@ -2,6 +2,7 @@ package cosmic import ( "fmt" + "strings" "testing" "github.com/MissionCriticalCloud/go-cosmic/v6/cosmic" @@ -117,6 +118,6 @@ resource "cosmic_vpc" "foo" { network_domain = "terraform-domain" zone = "%s" }`, - COSMIC_VPC_OFFERING, + strings.ToLower(COSMIC_VPC_OFFERING), COSMIC_ZONE, )