Quick Answer
# Usually succeeds on retry
terraform apply
# If it keeps failing, reduce parallelism
terraform apply -parallelism=5
The Error
Error: creating EC2 Instance: Post "https://ec2.us-east-1.amazonaws.com/":
context deadline exceeded
Error: waiting for RDS Instance (mydb) create: context deadline exceeded
Or:
Error: Provider "aws" produced an unexpected error:
Post https://sts.amazonaws.com/: context deadline exceeded (Client.Timeout exceeded)
What Causes This
- API throttling — too many concurrent requests hit rate limits
- Slow resource creation — RDS, EKS, CloudFront can take 10-30 minutes
- Network issues — VPN, proxy, DNS resolution failures
- Large state — hundreds of resources cause slow plan/refresh
Solution 1: Retry
Most transient. Just run it again:
terraform apply
Terraform tracks what was created — it picks up where it left off.
Solution 2: Reduce Parallelism
Default parallelism is 10. Lower it when hitting API rate limits:
# Reduce to 5 concurrent operations
terraform apply -parallelism=5
# Very aggressive — useful for debugging
terraform apply -parallelism=1
Solution 3: Custom Resource Timeouts
Some resources take a long time. Override the default timeout:
resource "aws_db_instance" "main" {
engine = "postgres"
instance_class = "db.r6g.xlarge"
# ...
timeouts {
create = "60m" # Default is 40m
update = "80m"
delete = "60m"
}
}
resource "aws_eks_cluster" "main" {
name = "my-cluster"
role_arn = aws_iam_role.eks.arn
# ...
timeouts {
create = "30m"
update = "60m"
delete = "15m"
}
}
Common Resources That Need Extended Timeouts
| Resource | Default | Recommended |
|---|---|---|
aws_db_instance | 40m | 60m |
aws_eks_cluster | 30m | 45m |
aws_cloudfront_distribution | 70m | 90m |
aws_rds_cluster | 120m | 120m |
aws_elasticsearch_domain | 60m | 90m |
azurerm_kubernetes_cluster | 90m | 120m |
Solution 4: Debug Network Issues
# Test connectivity to AWS API
curl -v https://ec2.us-east-1.amazonaws.com/
# Check DNS resolution
nslookup ec2.us-east-1.amazonaws.com
# Enable Terraform debug logging
export TF_LOG=DEBUG
terraform apply 2>&1 | tee terraform-debug.log
# Check for proxy issues
echo $HTTPS_PROXY $HTTP_PROXY $NO_PROXY
Solution 5: Target Large Deployments
Break up massive applies:
# Deploy in stages
terraform apply -target=module.networking
terraform apply -target=module.database
terraform apply -target=module.application
terraform apply # Final pass for remaining resources
Solution 6: Increase HTTP Timeout (Provider Level)
provider "aws" {
region = "us-east-1"
# Increase HTTP client timeout
max_retries = 10
default_tags {
tags = {
ManagedBy = "terraform"
}
}
}
Prevention
- Use
-parallelism=5in CI/CD pipelines by default - Add
timeoutsblocks to slow resources (RDS, EKS, CloudFront) - Split large root modules into smaller ones
- Use
terraform plan -refresh=falsefor faster planning when debugging
Hands-On Courses
- Terraform for Beginners on CopyPasteLearn
- Terraform By Example — practical code examples
Conclusion
Context deadline exceeded means an API call timed out. Retry first — it usually works. If it keeps happening, reduce parallelism to 5, add timeouts blocks to slow resources, and check for network/VPN issues. For CI/CD, always set -parallelism=5 and add generous timeouts to RDS, EKS, and CloudFront resources.
