Skip to content

Commit

Permalink
Merge pull request #4511 from Cyb3r-Jak3/avoid-duplicate-list-item-cr…
Browse files Browse the repository at this point in the history
…eation

Don't set items for lists when not needed
  • Loading branch information
jacobbednarz authored Nov 13, 2024
2 parents a926ff0 + 2c128b7 commit c03faeb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
3 changes: 3 additions & 0 deletions .changelog/4511.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/cloudflare_list: Don't read list items if there are none configured
```
18 changes: 10 additions & 8 deletions internal/framework/service/list/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,17 @@ func (r *ListResource) Read(ctx context.Context, req resource.ReadRequest, resp
state.Description = types.StringValue(list.Description)
state.Kind = types.StringValue(list.Kind)

items, err := r.client.V1.ListListItems(ctx, cloudflare.AccountIdentifier(state.AccountID.ValueString()), cloudflare.ListListItemsParams{
ID: state.ID.ValueString(),
})
if err != nil {
resp.Diagnostics.AddError("Error reading List Items", err.Error())
return
}
if len(state.Items) > 0 {
items, err := r.client.V1.ListListItems(ctx, cloudflare.AccountIdentifier(state.AccountID.ValueString()), cloudflare.ListListItemsParams{
ID: state.ID.ValueString(),
})
if err != nil {
resp.Diagnostics.AddError("Error reading List Items", err.Error())
return
}

state.Items = buildListItemModels(items)
state.Items = buildListItemModels(items)
}

diags = resp.State.Set(ctx, &state)
resp.Diagnostics.Append(diags...)
Expand Down

0 comments on commit c03faeb

Please sign in to comment.