Scenario
You are deploying a production Terraform change. The plan proposes to create 50 resources. The apply starts. The first 30 succeed. The 31st fails with:
Error: error creating EC2 Instance: RequestLimitExceeded: Request
rate exceeded.
The apply terminates.
The state has 30 resources. The real world has 30 resources.
Your task
Identify the cause of the failure and recover. The remaining resources must be created.
Evidence to discover
# Check the apply command
terraform apply -parallelism=10
# Check the providers documentation
# (the AWS providers rate limit is documented)
# Check the recent API calls
aws cloudtrail lookup-events \
--lookup-attributes AttributeKey=EventName,AttributeValue=RunInstances
# Check the parallelism
terraform show -json production.tfplan | jq '.configuration.provider_configurations'
Questions to answer
- What is the rate limit?
- What is the current parallelism?
- What is the correct remediation?
- What is the verification step?
Recovery procedure
(Do not reveal this until the student has reasoned through the problem.)
- Identify the cause. The default parallelism (10) was too high for the AWS API rate limit.
- Reduce the parallelism.
terraform apply -parallelism=2
The lower parallelism reduces the rate of API calls.
- Re-apply.
terraform apply -parallelism=2
The apply creates the remaining resources.
- Verify the state.
terraform plan
The plan should be empty.
- Document the incident. The rate limit, the parallelism, the verification.
Remediation
- The cause was the AWS API rate limit.
- The default parallelism (10) was too high.
- The new parallelism (2) was below the rate limit.
- The apply succeeded with the lower parallelism.
- The plan is empty after the recovery.
Prevention
- Set the parallelism to a value the provider can sustain.
- Use preconditions to verify the environment.
- Document the rate limit in the configuration.
- Test the configuration in a development environment.
- Use the
--parallelismflag in CI.
What you learned
- The provider API rate limit is a real constraint.
- The parallelism is the rate of API calls.
- Lower parallelism reduces the rate, but increases the apply time.
- The verification is the plan must be empty.