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

Fix error handling in cloudflare_turnstile #3284

Merged
merged 1 commit into from
May 6, 2024
Merged
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/3284.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/cloudflare_turnstile: Fix error handling corrupting state
```
5 changes: 5 additions & 0 deletions internal/framework/service/turnstile/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ func (r *TurnstileWidgetResource) Create(ctx context.Context, req resource.Creat
})
if err != nil {
resp.Diagnostics.AddError("Error creating challenge widget", err.Error())
return
}

data = buildChallengeModelFromWidget(
Expand All @@ -96,6 +97,7 @@ func (r *TurnstileWidgetResource) Read(ctx context.Context, req resource.ReadReq

if err != nil {
resp.Diagnostics.AddError("Error reading challenge widget", err.Error())
return
}

data = buildChallengeModelFromWidget(
Expand Down Expand Up @@ -129,6 +131,7 @@ func (r *TurnstileWidgetResource) Update(ctx context.Context, req resource.Updat

if err != nil {
resp.Diagnostics.AddError("Error reading challenge widget", err.Error())
return
}

data = buildChallengeModelFromWidget(
Expand All @@ -151,13 +154,15 @@ func (r *TurnstileWidgetResource) Delete(ctx context.Context, req resource.Delet
err := r.client.V1.DeleteTurnstileWidget(ctx, cfv1.AccountIdentifier(data.AccountID.ValueString()), data.ID.ValueString())
if err != nil {
resp.Diagnostics.AddError("Error deleting challenge widget", err.Error())
return
}
}

func (r *TurnstileWidgetResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) {
idParts := strings.Split(req.ID, "/")
if len(idParts) != 2 {
resp.Diagnostics.AddError("Error importing challenge widget", "Invalid ID specified. Please specify the ID as \"accounts_id/sitekey\"")
return
}
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])...)
Expand Down
Loading