From 2c128b7d588ce5f0c87f3e5e125130b66e546d7e Mon Sep 17 00:00:00 2001 From: Cyb3r-Jak3 Date: Mon, 4 Nov 2024 23:22:19 -0500 Subject: [PATCH] Don't set items for lists when not needed --- .changelog/4511.txt | 3 +++ internal/framework/service/list/resource.go | 18 ++++++++++-------- 2 files changed, 13 insertions(+), 8 deletions(-) create mode 100644 .changelog/4511.txt diff --git a/.changelog/4511.txt b/.changelog/4511.txt new file mode 100644 index 0000000000..6e127e4922 --- /dev/null +++ b/.changelog/4511.txt @@ -0,0 +1,3 @@ +```release-note:bug +resource/cloudflare_list: Don't read list items if there are none configured +``` diff --git a/internal/framework/service/list/resource.go b/internal/framework/service/list/resource.go index 7cdc06a033..ba0cb10597 100644 --- a/internal/framework/service/list/resource.go +++ b/internal/framework/service/list/resource.go @@ -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...)