Skip to main content
Fix Terraform Error - Error Creating RDS - DBSubnetGroupNotFoundFault

Fix Terraform Error - Error Creating RDS - DBSubnetGroupNotFoundFault

Key Takeaway

How to fix DBSubnetGroupNotFoundFault when creating RDS instances in Terraform. Create subnet groups with subnets in multiple availability zones.

Table of Contents

The Error

Error creating DB Instance: DBSubnetGroupNotFoundFault: DBSubnetGroup 'X' not found

What Causes This

The DB subnet group referenced in your RDS configuration doesn’t exist or hasn’t been created yet. RDS instances in a VPC require a DB subnet group containing subnets in at least two different availability zones.

How to Fix It

Solution 1: Create the DB Subnet Group

resource "aws_db_subnet_group" "main" {
  name = "main-db-subnet-group"
  subnet_ids = [
    aws_subnet.private_a.id,
    aws_subnet.private_b.id,  # Must be in different AZs!
  ]
  tags = { Name = "Main DB subnet group" }
}

resource "aws_db_instance" "main" {
  identifier          = "production-db"
  engine              = "postgres"
  engine_version      = "15.4"
  instance_class      = "db.t3.micro"
  allocated_storage   = 20
  db_subnet_group_name = aws_db_subnet_group.main.name  # Reference here
  vpc_security_group_ids = [aws_security_group.db.id]
  skip_final_snapshot = true
}

Solution 2: Ensure Multiple AZs

data "aws_availability_zones" "available" {
  state = "available"
}

resource "aws_subnet" "private" {
  count             = 2
  vpc_id            = aws_vpc.main.id
  cidr_block        = "10.0.${count.index + 10}.0/24"
  availability_zone = data.aws_availability_zones.available.names[count.index]
}

resource "aws_db_subnet_group" "main" {
  name       = "main"
  subnet_ids = aws_subnet.private[*].id
}

Prevention Tips

  1. Pin provider versions — avoid surprise breaking changes
  2. Use CI/CD — catch errors before they hit production
  3. Test with terraform plan — always review before applying
  4. Keep Terraform updated — newer versions have better error messages
  5. Use terraform validate — catches syntax errors early

Hands-On Courses

Learn to avoid these errors with interactive, project-based courses:

Conclusion

This error is common and fixable. Follow the solutions above, and check our Terraform course for hands-on training that covers real-world troubleshooting scenarios.

🚀

Level Up Your Terraform Skills

Hands-on courses, books, and resources from Luca Berton

Luca Berton
Written by

Luca Berton

DevOps Engineer, AWS Partner, Terraform expert, and author. Creator of Ansible Pilot, Terraform Pilot, and CopyPasteLearn.