fix(account): prevent infinite pagination loop and duplicate results#6951
fix(account): prevent infinite pagination loop and duplicate results#6951AleksandrKls wants to merge 2 commits into
Conversation
…in cloudflare_accounts datasource Stop pagination when no progress is detected or when pages repeat, and deduplicate accounts by ID. This prevents long-running terraform plan (up to several minutes) and duplicate results when using account API tokens, where the Cloudflare /accounts API may return the same page repeatedly beyond total_pages.
|
I have pinged our engineering team to look at this PR. |
|
@rotem-cloud Sorry, I haven't created pull requests in Open Source before. Just to clarify, are you expecting me to write tests or will you test them yourself? |
|
@jhutchings1 Could you please clarify the details regarding my question above? |
|
Hi @AleksandrKls Join with Google Meet Please join to discuss about this |
|
I don't want to participate in meetings, but I can answer all your questions in text format. I'd also like to point out that we have a 10-hour time difference. I live in the UTC +3 time zone |
|
Hi @AleksandrKls, I'm looking into this and we suspect the root cause actually lies upstream in our Go SDK, so I'm exploring the option to patch it there instead. I'll circle back with an update this week. Thanks for opening the PR and providing these details! It helps a ton. |
As for testing the PR yourself, you're fine. I'll make sure we get the reproduction and test coverage sorted. |
It’s not about your Go SDK. The issue lies in how the API behaves when an account API token is used. You can take my curl request that I attached, send an HTTP request using an account API token (not to be confused with a user token), and you’ll observe the same behavior as with the data resource |
|
I've forwarded that info to the IAM team who owns this API to get it sorted in the API layer. Thanks @AleksandrKls |
Changes being requested
Fix infinite/long pagination loop and duplicate results in
cloudflare_accountsdatasource.When using an Account API token, the Cloudflare
/accountsAPI may return the same page repeatedly even whenresult_info.total_pages = 1.Example behavior observed:
/accounts?page=2+return the same account as page 1GetNextPage()untilmax_items(default 1000)terraform planmay take several minutesThis PR adds safeguards to handle non-progressing pagination:
account.idThis ensures fast execution and prevents duplicate results while preserving normal behavior for valid pagination.
Related to #5298
Acceptance test run results
Steps to run acceptance tests
N/A – no acceptance tests added (bug is specific to Account API token behavior and requires specific account/token setup to reproduce)
Test output
N/A
Additional context & links
Direct API reproduction using Account API token. Will be returned 5 duplicates: