From b704dd9260eb378bebfeb3d91b017f703979065c Mon Sep 17 00:00:00 2001 From: Jon Carl Date: Mon, 16 Sep 2024 16:53:27 -0600 Subject: [PATCH 1/3] feat: mark verification key as computed when changing to or from partial zone type Signed-off-by: Jon Carl --- internal/sdkv2provider/resource_cloudflare_zone.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/internal/sdkv2provider/resource_cloudflare_zone.go b/internal/sdkv2provider/resource_cloudflare_zone.go index 16c5364a9b..29fb0944ba 100644 --- a/internal/sdkv2provider/resource_cloudflare_zone.go +++ b/internal/sdkv2provider/resource_cloudflare_zone.go @@ -13,6 +13,7 @@ import ( "github.com/cloudflare/terraform-provider-cloudflare/internal/consts" "github.com/hashicorp/terraform-plugin-log/tflog" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) @@ -91,7 +92,13 @@ var ratePlans = map[string]subscriptionData{ func resourceCloudflareZone() *schema.Resource { return &schema.Resource{ - Schema: resourceCloudflareZoneSchema(), + Schema: resourceCloudflareZoneSchema(), + CustomizeDiff: customdiff.All( + customdiff.ComputedIf("verification_key", func(ctx context.Context, d *schema.ResourceDiff, meta interface{}) bool { + oldTypeVal, newTypeVal := d.GetChange("type") + return oldTypeVal == "partial" || newTypeVal == "partial" + }), + ), CreateContext: resourceCloudflareZoneCreate, ReadContext: resourceCloudflareZoneRead, UpdateContext: resourceCloudflareZoneUpdate, From c7226128a72dc005119862e8559bbc6fb4fde215 Mon Sep 17 00:00:00 2001 From: Jon Carl Date: Mon, 16 Sep 2024 20:19:32 -0600 Subject: [PATCH 2/3] update changelog Signed-off-by: Jon Carl --- .changelog/4019.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/4019.txt diff --git a/.changelog/4019.txt b/.changelog/4019.txt new file mode 100644 index 0000000000..236b03c33e --- /dev/null +++ b/.changelog/4019.txt @@ -0,0 +1,3 @@ +```release-note:bug +resource/cloudflare_zone: When changing `type` to or from `partial` the `verification_key` attribute will properly show that it will receive a new value. +``` From 0688779a618ba492f239f2bf3699b628144bf158 Mon Sep 17 00:00:00 2001 From: Jon Carl Date: Mon, 14 Oct 2024 16:31:19 -0600 Subject: [PATCH 3/3] only mark verification_key for change when type has a value change Signed-off-by: Jon Carl (cherry picked from commit 50feb4af646d992cd9db41142e2f0b0d91e70340) --- internal/sdkv2provider/resource_cloudflare_zone.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/internal/sdkv2provider/resource_cloudflare_zone.go b/internal/sdkv2provider/resource_cloudflare_zone.go index 29fb0944ba..ab05647f66 100644 --- a/internal/sdkv2provider/resource_cloudflare_zone.go +++ b/internal/sdkv2provider/resource_cloudflare_zone.go @@ -95,8 +95,11 @@ func resourceCloudflareZone() *schema.Resource { Schema: resourceCloudflareZoneSchema(), CustomizeDiff: customdiff.All( customdiff.ComputedIf("verification_key", func(ctx context.Context, d *schema.ResourceDiff, meta interface{}) bool { - oldTypeVal, newTypeVal := d.GetChange("type") - return oldTypeVal == "partial" || newTypeVal == "partial" + if d.HasChange("type") { + oldTypeVal, newTypeVal := d.GetChange("type") + return oldTypeVal == "partial" || newTypeVal == "partial" + } + return false }), ), CreateContext: resourceCloudflareZoneCreate,