Skip to content

Commit

Permalink
turnstile: rename id to sitekey
Browse files Browse the repository at this point in the history
  • Loading branch information
Aleksei Vasilev committed May 1, 2024
1 parent 79c3937 commit 0426688
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
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

0 comments on commit 0426688

Please sign in to comment.