Add rate limiting and retry configuration to Contentstack provider #44
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR implements rate limiting and automatic retry configuration for the Contentstack Terraform provider to address API rate limit issues that cause terraform operations to fail with 429 errors.
Changes implemented:
Provider Rate Limiting Configuration: Added three new optional provider attributes:
rate_limit
(float64): Maximum requests per second (defaults to 10.0 to comply with Contentstack API limits)rate_burst
(int): Maximum burst size for short bursts above the rate limit (defaults to 10)max_retries
(int): Maximum retry attempts for 429 responses with exponential backoff (defaults to 3)Integration with Enhanced SDK: Updated go.mod to use the enhanced contentstack-go-sdk that includes:
golang.org/x/time/rate
Retry-After
headersDocumentation Updates: Auto-generated provider documentation now includes all new rate limiting attributes with detailed descriptions.
Example Configurations: Added simplified examples demonstrating:
examples/provider/main.tf
)examples/rate-limiting/main.tf
)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).
The solution provides configurable rate limiting that prevents hitting API limits, plus automatic retry logic that gracefully handles any 429 responses that do occur, making Terraform operations reliable and robust.
Fixes #3
Related: contentstack-go-sdk#16
NEW FEATURES | UPGRADE NOTES | ENHANCEMENTS | BUG FIXES | EXPERIMENTS
rate_limit
provider attribute to configure API request throttlingrate_burst
provider attribute to allow controlled request burstsmax_retries
provider attribute to configure automatic retry attempts for 429 responses