Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

turnstile: rename id to sitekey #3280

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/3280.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/cloudflare_turnstile_widget: rename `id` to `sitekey`
```
2 changes: 1 addition & 1 deletion docs/resources/turnstile_widget.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
2 changes: 1 addition & 1 deletion internal/framework/service/turnstile/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
10 changes: 5 additions & 5 deletions internal/framework/service/turnstile/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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())
}
Expand All @@ -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(),
Expand All @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion internal/framework/service/turnstile/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down