diff --git a/.changelog/1828.txt b/.changelog/1828.txt new file mode 100644 index 0000000000..214335207b --- /dev/null +++ b/.changelog/1828.txt @@ -0,0 +1,3 @@ +```release-note:bug +resource/cloudflare_fallback_domain: fix perpetual changes due to ordering +``` diff --git a/internal/provider/resource_cloudflare_fallback_domain.go b/internal/provider/resource_cloudflare_fallback_domain.go index 640ed8373b..f75cda6c30 100644 --- a/internal/provider/resource_cloudflare_fallback_domain.go +++ b/internal/provider/resource_cloudflare_fallback_domain.go @@ -42,7 +42,7 @@ func resourceCloudflareFallbackDomainUpdate(ctx context.Context, d *schema.Resou client := meta.(*cloudflare.API) accountID := d.Get("account_id").(string) - domainList := expandFallbackDomains(d.Get("domains").([]interface{})) + domainList := expandFallbackDomains(d.Get("domains").(*schema.Set)) newFallbackDomains, err := client.UpdateFallbackDomain(ctx, accountID, domainList) if err != nil { @@ -88,7 +88,7 @@ func resourceCloudflareFallbackDomainImport(ctx context.Context, d *schema.Resou // flattenFallbackDomains accepts the cloudflare.FallbackDomain struct and returns the // schema representation for use in Terraform state. -func flattenFallbackDomains(domains []cloudflare.FallbackDomain) []interface{} { +func flattenFallbackDomains(domains []cloudflare.FallbackDomain) *schema.Set { schemaDomains := make([]interface{}, 0) for _, d := range domains { @@ -99,15 +99,15 @@ func flattenFallbackDomains(domains []cloudflare.FallbackDomain) []interface{} { }) } - return schemaDomains + return schema.NewSet(HashByMapKey("suffix"), schemaDomains) } // expandFallbackDomains accepts the schema representation of Fallback Domains and // returns a fully qualified struct. -func expandFallbackDomains(domains []interface{}) []cloudflare.FallbackDomain { +func expandFallbackDomains(domains *schema.Set) []cloudflare.FallbackDomain { domainList := make([]cloudflare.FallbackDomain, 0) - for _, domain := range domains { + for _, domain := range domains.List() { domainList = append(domainList, cloudflare.FallbackDomain{ Suffix: domain.(map[string]interface{})["suffix"].(string), Description: domain.(map[string]interface{})["description"].(string), diff --git a/internal/provider/resource_cloudflare_fallback_domain_test.go b/internal/provider/resource_cloudflare_fallback_domain_test.go index 6bc6fbce9f..6771142557 100644 --- a/internal/provider/resource_cloudflare_fallback_domain_test.go +++ b/internal/provider/resource_cloudflare_fallback_domain_test.go @@ -29,7 +29,7 @@ func TestAccCloudflareFallbackDomain(t *testing.T) { resource.Test(t, resource.TestCase{ CheckDestroy: testAccCheckCloudflareFallbackDomainDestroy, PreCheck: func() { - testAccessAccPreCheck(t) + testAccPreCheck(t) }, ProviderFactories: providerFactories, Steps: []resource.TestStep{ diff --git a/internal/provider/schema_cloudflare_fallback_domain.go b/internal/provider/schema_cloudflare_fallback_domain.go index 1b3143051d..0726f4f410 100644 --- a/internal/provider/schema_cloudflare_fallback_domain.go +++ b/internal/provider/schema_cloudflare_fallback_domain.go @@ -13,7 +13,7 @@ func resourceCloudflareFallbackDomainSchema() map[string]*schema.Schema { }, "domains": { Required: true, - Type: schema.TypeList, + Type: schema.TypeSet, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "suffix": {