Skip to content

Commit 24226cd

Browse files
authoredMay 6, 2024
Merge pull request #3284 from punkeel/maxime/turnstile-err
Fix error handling in cloudflare_turnstile
2 parents ba46db6 + 3ef096f commit 24226cd

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed
 

‎.changelog/3284.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:bug
2+
resource/cloudflare_turnstile: Fix error handling corrupting state
3+
```

‎internal/framework/service/turnstile/resource.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ func (r *TurnstileWidgetResource) Create(ctx context.Context, req resource.Creat
7373
})
7474
if err != nil {
7575
resp.Diagnostics.AddError("Error creating challenge widget", err.Error())
76+
return
7677
}
7778

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

9798
if err != nil {
9899
resp.Diagnostics.AddError("Error reading challenge widget", err.Error())
100+
return
99101
}
100102

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

130132
if err != nil {
131133
resp.Diagnostics.AddError("Error reading challenge widget", err.Error())
134+
return
132135
}
133136

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

157161
func (r *TurnstileWidgetResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) {
158162
idParts := strings.Split(req.ID, "/")
159163
if len(idParts) != 2 {
160164
resp.Diagnostics.AddError("Error importing challenge widget", "Invalid ID specified. Please specify the ID as \"accounts_id/sitekey\"")
165+
return
161166
}
162167
resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("account_id"), idParts[0])...)
163168
resp.Diagnostics.Append(resp.State.SetAttribute(ctx, path.Root("id"), idParts[1])...)

0 commit comments

Comments
 (0)