Fix Terraform Error: CloudWatch Log Group Already Exists
Fix terraform CloudWatch Log Group ResourceAlreadyExistsException. Import orphaned log groups, prevent Lambda auto-creation
DevOps
How to fix RouteAlreadyExists errors when managing VPC route tables in Terraform. Handle duplicate routes, inline vs separate resources, and default route...
A route with that destination CIDR already exists in the route table. Either import the existing route, remove the duplicate definition, or switch from inline routes to separate aws_route resources (or vice versa). Never mix inline and separate routes for the same route table.
Error creating Route: RouteAlreadyExists: The route identified by 0.0.0.0/0 already existsOr with specific CIDRs:
Error creating Route: RouteAlreadyExists: The route identified by 10.0.0.0/16 already existsSomeone added the route manually in the AWS Console, or another tool created it.
# ❌ WRONG — this creates the same route twice
resource "aws_route_table" "public" {
vpc_id = aws_vpc.main.id
route {
cidr_block = "0.0.0.0/0" # Inline route
gateway_id = aws_internet_gateway.main.id
}
}
resource "aws_route" "internet" {
route_table_id = aws_route_table.public.id
destination_cidr_block = "0.0.0.0/0" # Separate route — CONFLICT!
gateway_id = aws_internet_gateway.main.id
}The same route defined in two different .tf files.
AWS creates a local route (e.g., 10.0.0.0/16 → local) automatically — you can't override it.
# Format: route_table_id_destination_cidr
terraform import aws_route.internet rtb-0123456789abcdef0_0.0.0.0/0resource "aws_route_table" "public" {
vpc_id = aws_vpc.main.id
# NO inline routes
}
resource "aws_route" "internet" {
route_table_id = aws_route_table.public.id
destination_cidr_block = "0.0.0.0/0"
gateway_id = aws_internet_gateway.main.id
}
resource "aws_route" "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
}resource "aws_route_table" "public" {
vpc_id = aws_vpc.main.id
route {
cidr_block = "0.0.0.0/0"
gateway_id = aws_internet_gateway.main.id
}
route {
cidr_block = "10.1.0.0/16"
vpc_peering_connection_id = aws_vpc_peering_connection.peer.id
}
}# Search for duplicate route definitions
grep -rn 'destination_cidr_block.*0.0.0.0/0' *.tf modules/**/*.tf| Approach | Pros | Cons |
|---|---|---|
Inline (route {}) | Simple, all in one place | Manages ALL routes — can't mix |
Separate (aws_route) | Granular control, modular | More resources to manage |
Rule: Pick one approach per route table and stick with it.
.tf files?terraform plan to catch conflicts before applyingRouteAlreadyExists means the route exists — either outside Terraform or as a duplicate definition. Import it, remove the duplicate, and never mix inline and separate route resources on the same route table.
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.