Skip to content

Add rate limiting and retry configuration to Contentstack provider#44

Merged
demeyerthom merged 5 commits into
labd:mainfrom
robertolosanno-e2x:feature/rate-limiting-provider
May 22, 2026
Merged

Add rate limiting and retry configuration to Contentstack provider#44
demeyerthom merged 5 commits into
labd:mainfrom
robertolosanno-e2x:feature/rate-limiting-provider

Conversation

@robertolosanno-e2x

@robertolosanno-e2x robertolosanno-e2x commented Sep 18, 2025

Copy link
Copy Markdown
Contributor

This PR adds automatic retry configuration to the Contentstack Terraform provider to address API rate limit issues that cause Terraform operations to fail with 429 errors.

Changes implemented:

  1. Provider Retry Configuration: Added three new optional provider attributes:

    • max_retries (int): Maximum retry attempts for 429 responses with exponential backoff (defaults to 3)
    • retry_wait_min (int): Minimum wait time in seconds between retries (defaults to 1)
    • retry_wait_max (int): Maximum wait time in seconds between retries (defaults to 30)
  2. Retry Implementation: Uses go-retryablehttp to wrap the SDK's HTTP client with automatic retry logic:

    • Retries only on 429 (Too Many Requests) responses
    • Exponential backoff between retries, bounded by retry_wait_min and retry_wait_max
    • No changes required to contentstack-go-sdk
  3. Documentation Updates: Auto-generated provider documentation now includes all new retry attributes with detailed descriptions.

  4. Example Configuration: Updated examples/provider/main.tf to demonstrate retry configuration alongside the standard provider setup.

Rationale:
Contentstack's Management API has a 10 requests/second rate limit. When Terraform makes concurrent requests during plan/apply operations with multiple resources, it frequently hits 429 errors causing operations to fail. This is particularly problematic for users managing large numbers of content types and global fields (~35+ resources as mentioned in the related issue).

This PR ships retry logic as a self-contained change with no SDK dependency. Proactive rate limiting (token bucket) will follow in a separate PR once contentstack-go-sdk#17 is merged.

Fixes #3

NEW FEATURES | BUG FIXES

  • NEW FEATURE: Added max_retries provider attribute to configure automatic retry attempts for 429 responses
  • NEW FEATURE: Added retry_wait_min provider attribute to configure minimum wait time between retries
  • NEW FEATURE: Added retry_wait_max provider attribute to configure maximum wait time between retries
  • BUG FIX: Resolved 429 "Too Many Requests" errors that caused Terraform operations to fail

- Add rate_limit, rate_burst, and max_retries provider attributes
- Update provider schema to support new rate limiting options
- Add automatic retry logic integration with contentstack-go-sdk
- Update provider documentation with new attributes
- Add simplified examples for provider and rate-limiting configurations
- Update go.mod to use enhanced contentstack-go-sdk with rate limiting

This enables reliable Terraform operations by automatically handling
Contentstack API rate limits (10 req/sec) with configurable throttling
and exponential backoff retry logic for 429 responses.

Related: contentstack-go-sdk rate limiting implementation
- Add retryableRoundTripper for seamless SDK integration
- Implement retry policy for 429 responses only
- Add max_retries, retry_wait_min, retry_wait_max provider attributes
- Update examples and documentation
- Use exponential backoff with configurable wait times
- Maintain compatibility with existing rate limiting
@robertolosanno-e2x

Copy link
Copy Markdown
Contributor Author

Hi @demeyerthom ,
I was wondering if you have a minute to have a look at this PR.
Thanks

@demeyerthom demeyerthom left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks good! I left 2 comments to fix.

Can you also add a changie file for the changelog? It triggers our deployment processes:

Comment thread internal/provider/provider.go Outdated
BaseURL: config.BaseURL.Value,
AuthToken: config.AuthToken.Value,
HTTPClient: httpClient,
RateLimit: config.RateLimit.Value,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think those fields are not part of the config are they?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @demeyerthom,
Good catch! Those RateLimit and RateBurst fields are part of the SDK changes I've proposed in contentstack-go-sdk PR labd/contentstack-go-sdk#17.
The fields aren't in the published SDK (v0.1.0) yet, so this terraform provider PR depends on those SDK changes being merged first.
Would you be open to reviewing and merging the SDK PR first? Once that's released, this provider PR will work with the new SDK version. Happy to make any adjustments needed on either PR!
Thanks for your time reviewing this!

Comment thread examples/rate-limiting/main.tf Outdated
@@ -0,0 +1,33 @@
terraform {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This bit will not show in the docs. You want to add it to examples/provider/main.tf, and then run go generate to generate the correct docs for it to show

@rasmus-lisborg-19 rasmus-lisborg-19 May 14, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@robertolosanno-e2x are you okay to sort this comment out? Or alternatively allow me to push to your fork :)

@rasmus-lisborg-19

Copy link
Copy Markdown
Contributor

I've recently started using this provider on a project, and am unfortunately running into the same issue as @robertolosanno-e2x, of getting a bunch of 429 errors when running tf plan. Any chance we can have this and the dependant pr reviewed?

@robertolosanno-e2x

Copy link
Copy Markdown
Contributor Author

Hi @demeyerthom ,

Following your feedback, I've updated this PR to address the dependency on unreleased SDK changes.

What changed in this PR:

  • Removed rate_limit and rate_burst — these required fields in management.ClientConfig that don't exist in the published SDK v0.1.1

  • Retry logic (via go-retryablehttp) is self-contained with no SDK dependency and remains in place

What this PR now ships:

  • max_retries, retry_wait_min, retry_wait_max provider attributes
  • Automatic retry with exponential backoff on 429 responses

Plan for rate limiting:
Rate limiting (token bucket, rate_limit / rate_burst) will follow in a separate PR once contentstack-go-sdk#17 is reviewed and merged.

This should unblock users hitting 429 errors today (like @rasmus-lisborg-19) while keeping the dependency chain clean.

@rasmus-lisborg-19

Copy link
Copy Markdown
Contributor

I think all comments have been addressed. Any chance we could get it re-reviewed @demeyerthom ?

@demeyerthom demeyerthom left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@demeyerthom demeyerthom merged commit cc4e438 into labd:main May 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

add property to configure rate limit

3 participants