Fix Terraform Error: CloudWatch Log Group Already Exists
Fix terraform CloudWatch Log Group ResourceAlreadyExistsException. Import orphaned log groups, prevent Lambda auto-creation
DevOps
Fix DBClusterNotFoundFault when creating AWS Neptune clusters in Terraform. Handle subnet group configuration, parameter groups, and IAM role dependencies.
The Neptune cluster creation failed because of missing or misconfigured dependencies — typically the DB subnet group doesn't exist, the VPC subnets span fewer than 2 AZs, or the IAM role isn't ready. Fix subnet group coverage, ensure 2+ AZs, and add explicit depends_on for IAM roles.
Error: error creating Neptune Cluster: DBClusterNotFoundFault:
DB cluster not foundError: error creating Neptune Cluster:
DBSubnetGroupDoesNotCoverEnoughAZsresource "aws_neptune_subnet_group" "main" {
name = "${var.project}-neptune"
subnet_ids = aws_subnet.private[*].id # Must span 2+ AZs
tags = { Name = "${var.project}-neptune-subnet-group" }
}
resource "aws_neptune_cluster_parameter_group" "main" {
family = "neptune1.3"
name = "${var.project}-neptune-params"
parameter {
name = "neptune_enable_audit_log"
value = "1"
}
}
resource "aws_neptune_cluster" "main" {
cluster_identifier = "${var.project}-neptune"
engine = "neptune"
neptune_subnet_group_name = aws_neptune_subnet_group.main.name
neptune_cluster_parameter_group_name = aws_neptune_cluster_parameter_group.main.name
vpc_security_group_ids = [aws_security_group.neptune.id]
iam_database_authentication_enabled = true
skip_final_snapshot = true
depends_on = [aws_neptune_subnet_group.main]
}
resource "aws_neptune_cluster_instance" "main" {
count = 2
cluster_identifier = aws_neptune_cluster.main.id
instance_class = "db.r6g.large"
engine = "neptune"
tags = { Name = "${var.project}-neptune-${count.index}" }
}# Verify subnets span multiple AZs
data "aws_availability_zones" "available" {
state = "available"
}
resource "aws_subnet" "private" {
count = 3 # 3 AZs for high availability
vpc_id = aws_vpc.main.id
cidr_block = cidrsubnet(aws_vpc.main.cidr_block, 8, count.index + 10)
availability_zone = data.aws_availability_zones.available.names[count.index]
}resource "aws_security_group" "neptune" {
name = "${var.project}-neptune"
vpc_id = aws_vpc.main.id
ingress {
from_port = 8182
to_port = 8182
protocol = "tcp"
security_groups = [aws_security_group.app.id]
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
}Neptune requires a subnet group spanning 2+ AZs, proper security groups (port 8182), and correctly configured parameter groups. Use explicit resource references instead of name strings, and add depends_on when Terraform can't infer the dependency automatically.
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.