diff --git a/.changelog/1706.txt b/.changelog/1706.txt new file mode 100644 index 0000000000..356f384718 --- /dev/null +++ b/.changelog/1706.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +resource/cloudflare_teams_list: handle pagination for larger Team List accounts +``` diff --git a/internal/provider/resource_cloudflare_teams_list.go b/internal/provider/resource_cloudflare_teams_list.go index ef8c39523f..48dc38c2df 100644 --- a/internal/provider/resource_cloudflare_teams_list.go +++ b/internal/provider/resource_cloudflare_teams_list.go @@ -60,6 +60,7 @@ func resourceCloudflareTeamsListRead(ctx context.Context, d *schema.ResourceData identifier := cloudflare.AccountIdentifier(accountID) list, err := client.GetTeamsList(ctx, identifier, d.Id()) + if err != nil { var notFoundError *cloudflare.NotFoundError if errors.As(err, ¬FoundError) { @@ -80,6 +81,7 @@ func resourceCloudflareTeamsListRead(ctx context.Context, d *schema.ResourceData if err != nil { return diag.FromErr(fmt.Errorf("error finding Teams List %q: %w", d.Id(), err)) } + d.Set("items", convertListItemsToSchema(listItems)) return nil @@ -114,7 +116,9 @@ func resourceCloudflareTeamsListUpdate(ctx context.Context, d *schema.ResourceDa newItems := newItemsIface.(*schema.Set).List() patchTeamsList := cloudflare.PatchTeamsListParams{ID: d.Id()} setListItemDiff(&patchTeamsList, oldItems, newItems) + l, err := client.PatchTeamsList(ctx, identifier, patchTeamsList) + if err != nil { return diag.FromErr(fmt.Errorf("error updating Teams List for account %q: %w", accountID, err)) } diff --git a/internal/provider/resource_cloudflare_teams_list_test.go b/internal/provider/resource_cloudflare_teams_list_test.go index b4e0289130..49eb358cd5 100644 --- a/internal/provider/resource_cloudflare_teams_list_test.go +++ b/internal/provider/resource_cloudflare_teams_list_test.go @@ -4,6 +4,8 @@ import ( "context" "fmt" "os" + "strconv" + "strings" "testing" "github.com/cloudflare/cloudflare-go" @@ -11,7 +13,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" ) -func TestAccCloudflareTeamsListBasic(t *testing.T) { +func TestAccCloudflareTeamsList_Basic(t *testing.T) { // Temporarily unset CLOUDFLARE_API_TOKEN if it is set as the Access // service does not yet support the API tokens and it results in // misleading state error messages. @@ -45,7 +47,40 @@ func TestAccCloudflareTeamsListBasic(t *testing.T) { }) } -func TestAccCloudflareTeamsListReordered(t *testing.T) { +func TestAccCloudflareTeamsList_LottaListItems(t *testing.T) { + // Temporarily unset CLOUDFLARE_API_TOKEN if it is set as the Access + // service does not yet support the API tokens and it results in + // misleading state error messages. + if os.Getenv("CLOUDFLARE_API_TOKEN") != "" { + t.Setenv("CLOUDFLARE_API_TOKEN", "") + } + + rnd := generateRandomResourceName() + name := fmt.Sprintf("cloudflare_teams_list.%s", rnd) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { + testAccPreCheck(t) + testAccessAccPreCheck(t) + }, + ProviderFactories: providerFactories, + CheckDestroy: testAccCheckCloudflareTeamsListDestroy, + Steps: []resource.TestStep{ + { + Config: testAccCloudflareTeamsListConfigBigItemCount(rnd, accountID), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(name, "account_id", accountID), + resource.TestCheckResourceAttr(name, "name", rnd), + resource.TestCheckResourceAttr(name, "type", "SERIAL"), + resource.TestCheckResourceAttr(name, "description", "My description"), + resource.TestCheckResourceAttr(name, "items.#", "1000"), + ), + }, + }, + }) +} + +func TestAccCloudflareTeamsList_Reordered(t *testing.T) { // Temporarily unset CLOUDFLARE_API_TOKEN if it is set as the Access // service does not yet support the API tokens and it results in // misleading state error messages. @@ -85,6 +120,23 @@ resource "cloudflare_teams_list" "%[1]s" { `, rnd, accountID) } +func testAccCloudflareTeamsListConfigBigItemCount(rnd, accountID string) string { + items := []string{} + for i := 0; i < 1000; i++ { + items = append(items, `"example-`+strconv.Itoa(i)+`"`) + } + + return fmt.Sprintf(` +resource "cloudflare_teams_list" "%[1]s" { + account_id = "%[2]s" + name = "%[1]s" + description = "My description" + type = "SERIAL" + items = [%[3]s] +} +`, rnd, accountID, strings.Join(items, ",")) +} + func testAccCloudflareTeamsListConfigReorderedItems(rnd, accountID string) string { return fmt.Sprintf(` resource "cloudflare_teams_list" "%[1]s" {