Fix Terraform Error: CloudWatch Log Group Already Exists
Fix terraform CloudWatch Log Group ResourceAlreadyExistsException. Import orphaned log groups, prevent Lambda auto-creation
DevOps
Fix timeout errors in Terraform when resources take too long to create. Increase timeouts, handle slow cloud operations, and debug hanging applies.
The resource didn't reach a ready state within Terraform's timeout period. Add a timeouts block with longer values, or fix the underlying issue (misconfigured networking, missing IAM permissions, or unhealthy resource).
Error: timeout while waiting for state to become 'ACTIVE'
(last state: 'CREATING', timeout: 10m0s)Error: Error waiting for RDS instance to be available: timeout
while waiting for state to become 'available'resource "aws_db_instance" "main" {
identifier = "production-db"
engine = "postgres"
instance_class = "db.r6g.large"
timeouts {
create = "60m" # RDS can take 20+ minutes
update = "60m"
delete = "60m"
}
}
resource "aws_eks_cluster" "main" {
name = "production"
role_arn = aws_iam_role.eks.arn
timeouts {
create = "30m" # EKS clusters take 15-20 minutes
update = "30m"
delete = "30m"
}
}
resource "aws_elasticache_cluster" "main" {
cluster_id = "cache"
engine = "redis"
timeouts {
create = "30m"
delete = "30m"
}
}# Resources in private subnets need NAT for internet access
resource "aws_nat_gateway" "main" {
allocation_id = aws_eip.nat.id
subnet_id = aws_subnet.public.id
}
resource "aws_route" "private_nat" {
route_table_id = aws_route_table.private.id
destination_cidr_block = "0.0.0.0/0"
nat_gateway_id = aws_nat_gateway.main.id
}# Check what's happening with the resource
aws rds describe-db-instances --db-instance-identifier production-db \
--query 'DBInstances[0].DBInstanceStatus'
# Check EKS cluster status
aws eks describe-cluster --name production \
--query 'cluster.status'| Resource | Typical Time | Recommended Timeout |
|---|---|---|
| EC2 instance | 1-3 min | 10m (default) |
| RDS instance | 10-20 min | 60m |
| EKS cluster | 15-20 min | 30m |
| ElastiCache | 5-15 min | 30m |
| NAT Gateway | 2-5 min | 10m |
| CloudFront | 15-30 min | 60m |
| Redshift cluster | 10-20 min | 60m |
Timeouts usually mean the resource is slow (normal for RDS, EKS, CloudFront) or something is blocking it (networking, permissions). Increase the timeouts block first, then check the resource status in the cloud console to understand if it's still creating or stuck.
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.