Scenario
You are deploying a configuration that creates 50 EC2 instances. The apply creates 30 instances, then fails with:
aws_instance.web31: Creating...
aws_instance.web31: Error: error creating EC2 Instance:
VcpuLimitExceeded: You have requested more vCPU capacity than allowed.
The state has 30 instances. The apply is incomplete.
Your task
Recover from the partial apply.
Evidence to discover
# Check the current resource count
terraform state list | wc -l
# Check the quota
aws service-quotas get-service-quota \
--service-code ec2 \
--quota-code L-1216C47A
# Check the partial apply
aws ec2 describe-instances \
--filters "Name=tag:Environment,Values=production" \
--query "Reservations[].Instances[].[InstanceId]"
Questions to answer
- What is the quota? The quota is the limit on the number of resources.
- What is the current usage? The current usage is the number of resources created.
- What is the quota increase request path? The quota increase request is submitted through the providers portal.
- What is the recovery procedure? The recovery is to request the quota increase, then re-apply.
Recovery procedure
(Do not reveal this until the student has reasoned through the problem.)
- Stop the apply. The apply is incomplete.
- Investigate the partial state. The state has 30 instances. The real world has 30 instances.
- Request a quota increase.
aws service-quotas request-service-quota-increase \
--service-code ec2 \
--quota-code L-1216C47A \
--desired-value 100
- Wait for the quota increase. The quota increase is approved by the provider.
- Verify the new quota.
aws service-quotas get-service-quota \
--service-code ec2 \
--quota-code L-1216C47A
- Re-run the plan.
terraform plan
The plan should show the remaining 20 instances.
- Apply.
terraform apply
The apply creates the remaining 20 instances.
- Verify the state.
terraform state list | wc -l
The state has 50 instances.
Remediation
The cause was the quota exceeded. The team requested a quota increase. The apply completed after the quota was increased.
Prevention
- Check the quota before the apply.
- Request a quota increase in advance.
- Use smaller batches when the quota is near the limit.
- Document the quota usage in the runbook.
What you learned
- A quota is a real-world constraint, not a configuration constraint.
- The quota is checked by the provider, not by Terraform.
- The quota is increased by the providers portal, not by Terraform.
- The recovery is to increase the quota, then re-apply.
- The partial apply is recoverable.