Fix Terraform Error: CloudWatch Log Group Already Exists
Fix terraform CloudWatch Log Group ResourceAlreadyExistsException. Import orphaned log groups, prevent Lambda auto-creation
DevOps
Fix terraform context deadline exceeded errors caused by API timeouts. Covers retry, reduced parallelism, custom timeouts, network debugging
# Usually succeeds on retry
terraform apply
# If it keeps failing, reduce parallelism
terraform apply -parallelism=5Error: creating EC2 Instance: Post "https://ec2.us-east-1.amazonaws.com/":
context deadline exceeded
Error: waiting for RDS Instance (mydb) create: context deadline exceededOr:
Error: Provider "aws" produced an unexpected error:
Post https://sts.amazonaws.com/: context deadline exceeded (Client.Timeout exceeded)Most transient. Just run it again:
terraform applyTerraform tracks what was created — it picks up where it left off.
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=1Some 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"
}
}| 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 |
# 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_PROXYBreak 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 resourcesprovider "aws" {
region = "us-east-1"
# Increase HTTP client timeout
max_retries = 10
default_tags {
tags = {
ManagedBy = "terraform"
}
}
}-parallelism=5 in CI/CD pipelines by defaulttimeouts blocks to slow resources (RDS, EKS, CloudFront)terraform plan -refresh=false for faster planning when debuggingContext 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.
Fix terraform CloudWatch Log Group ResourceAlreadyExistsException. Import orphaned log groups, prevent Lambda auto-creation
Fix terraform import errors when a resource already exists in state. Covers state rm, state show, reimport workflow, import blocks
Fix terraform too many command line arguments errors. Correct -var syntax, quote values with spaces, and learn proper Terraform CLI argument format for plan
Fix terraform invalid escape sequence errors. Double backslashes for Windows paths, use heredocs for regex, and learn all valid HCL escape sequences.