From 0426688b29016da0355bc8373f5a6332d0f2e583 Mon Sep 17 00:00:00 2001 From: Aleksei Vasilev Date: Wed, 1 May 2024 22:05:57 +0200 Subject: [PATCH] turnstile: rename id to sitekey Fixes #3093 --- docs/resources/turnstile_widget.md | 2 +- internal/framework/service/turnstile/model.go | 2 +- internal/framework/service/turnstile/resource.go | 10 +++++----- internal/framework/service/turnstile/schema.go | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/docs/resources/turnstile_widget.md b/docs/resources/turnstile_widget.md index e96c95a3fe..55b6733ffd 100644 --- a/docs/resources/turnstile_widget.md +++ b/docs/resources/turnstile_widget.md @@ -34,7 +34,7 @@ resource "cloudflare_turnstile_widget" "example" { ### Optional - `bot_fight_mode` (Boolean) If bot_fight_mode is set to true, Cloudflare issues computationally expensive challenges in response to malicious bots (Enterprise only). -- `id` (String) The identifier of this resource. This is the site key value. +- `sitekey` (String) The identifier of this resource. This is the site key value. - `offlabel` (Boolean) Do not show any Cloudflare branding on the widget (Enterprise only). - `region` (String) Region where this widget can be used. diff --git a/internal/framework/service/turnstile/model.go b/internal/framework/service/turnstile/model.go index aeffe14da7..4a752ca3f9 100644 --- a/internal/framework/service/turnstile/model.go +++ b/internal/framework/service/turnstile/model.go @@ -4,7 +4,7 @@ import "github.com/hashicorp/terraform-plugin-framework/types" type TurnstileWidgetModel struct { AccountID types.String `tfsdk:"account_id"` - ID types.String `tfsdk:"id"` + SiteKey types.String `tfsdk:"sitekey"` Domains types.Set `tfsdk:"domains"` Name types.String `tfsdk:"name"` Secret types.String `tfsdk:"secret"` diff --git a/internal/framework/service/turnstile/resource.go b/internal/framework/service/turnstile/resource.go index 8d67710fd6..322719f784 100644 --- a/internal/framework/service/turnstile/resource.go +++ b/internal/framework/service/turnstile/resource.go @@ -92,7 +92,7 @@ func (r *TurnstileWidgetResource) Read(ctx context.Context, req resource.ReadReq return } - widget, err := r.client.V1.GetTurnstileWidget(ctx, cfv1.AccountIdentifier(data.AccountID.ValueString()), data.ID.ValueString()) + widget, err := r.client.V1.GetTurnstileWidget(ctx, cfv1.AccountIdentifier(data.AccountID.ValueString()), data.SiteKey.ValueString()) if err != nil { resp.Diagnostics.AddError("Error reading challenge widget", err.Error()) @@ -148,7 +148,7 @@ func (r *TurnstileWidgetResource) Delete(ctx context.Context, req resource.Delet return } - err := r.client.V1.DeleteTurnstileWidget(ctx, cfv1.AccountIdentifier(data.AccountID.ValueString()), data.ID.ValueString()) + err := r.client.V1.DeleteTurnstileWidget(ctx, cfv1.AccountIdentifier(data.AccountID.ValueString()), data.SiteKey.ValueString()) if err != nil { resp.Diagnostics.AddError("Error deleting challenge widget", err.Error()) } @@ -160,12 +160,12 @@ func (r *TurnstileWidgetResource) ImportState(ctx context.Context, req resource. resp.Diagnostics.AddError("Error importing challenge widget", "Invalid ID specified. Please specify the ID as \"accounts_id/sitekey\"") } resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("account_id"), idParts[0])...) - resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("id"), idParts[1])...) + resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("sitekey"), idParts[1])...) } func buildChallengeWidgetFromModel(ctx context.Context, widget *TurnstileWidgetModel) cfv1.TurnstileWidget { built := cfv1.TurnstileWidget{ - SiteKey: widget.ID.ValueString(), + SiteKey: widget.SiteKey.ValueString(), Name: widget.Name.ValueString(), BotFightMode: widget.BotFightMode.ValueBool(), Mode: widget.Mode.ValueString(), @@ -180,7 +180,7 @@ func buildChallengeWidgetFromModel(ctx context.Context, widget *TurnstileWidgetM func buildChallengeModelFromWidget(accountID types.String, widget cfv1.TurnstileWidget) *TurnstileWidgetModel { built := TurnstileWidgetModel{ AccountID: accountID, - ID: flatteners.String(widget.SiteKey), + SiteKey: flatteners.String(widget.SiteKey), Secret: flatteners.String(widget.Secret), BotFightMode: types.BoolValue(widget.BotFightMode), Name: flatteners.String(widget.Name), diff --git a/internal/framework/service/turnstile/schema.go b/internal/framework/service/turnstile/schema.go index 2a0408e64f..23d2103f2a 100644 --- a/internal/framework/service/turnstile/schema.go +++ b/internal/framework/service/turnstile/schema.go @@ -25,7 +25,7 @@ func (r *TurnstileWidgetResource) Schema(ctx context.Context, req resource.Schem `), Attributes: map[string]schema.Attribute{ - consts.IDSchemaKey: schema.StringAttribute{ + "sitekey": schema.StringAttribute{ Computed: true, Optional: true, MarkdownDescription: consts.IDSchemaDescription + " This is the site key value.",