Hi there,
I've got terraform file that looks like this
terraform {
backend "s3" {
bucket = "s3-terraform-state-backend"
region = "eu-central-1"
key = "app/terraform.tfstate"
}
}
provider "aws" {
region = "eu-central-1"
}
resource "aws_db_instance" "default" {
availability_zone = "eu-central-1a"
allocated_storage = 10
storage_type = "gp2"
engine = "postgres"
instance_class = "db.t2.micro"
name = "core"
port = 5432
engine_version = "10"
skip_final_snapshot = true
final_snapshot_identifier = "snap-1"
username = "${var.username}"
password = "${var.password}"
}
resource "aws_instance" "default" {
ami = "ami-ac442ac3"
availability_zone = "eu-central-1a"
instance_type = "t2.micro"
associate_public_ip_address = true
}
variable "username" {}
variable "password" {}
But when I try to apply it I get this error
aws_db_instance.default: 1 error(s) occurred:
aws_db_instance.default: Error creating DB Instance: InvalidVPCNetworkStateFault: The VPC vpc-4648d12d associated with the default subnet group does not exist. Please delete the default subnet group or specify another subnet group.
status code: 400, request id: f16c0152-187e-4aff-b510-a9dfe4a80438
EC2 is being created successfully though.
What is the problem?
@lapots Has the default VPC in the eu-central-1
region been deleted?
Each region gets a default RDS DB subnet group that includes the default subnets in the default VPC for that region. If no db_subnet_group_name
attribute is specified when an RDS DB Instance is created then this default subnet group is used.
I guess that if the default VPC for the region is deleted then this default RDS DB subnet group is NOT deleted and you are left with a dangling reference to the non-existent default VPC.
I suggest adding a new RDS DB subnet group or using an existing non-default one and specifying that subnet group's name in the db_subnet_group_name
attribute.
@ewbankkit well, yeah it seems there was a conflict with my subnet groups. I once create RDS in the past, then deleted but it seems subnet groups used old VPC id. I recreated everything and it started to work.
I know it's closed, but to help someone searching on google, I've deleted a vpc and created a new default vpc and I got this problem, to solve this, I go to Amazon RDS > Subnet groups > and I deleted the subnet group, and worked
Thanks DigaoParceiro. I thought all VPC stuff was in one place under Services, VPC. My error was referring to a vpc that I could not see and I thought my settings must be really screwed up.
I has not seen RDS, subnet groups.
I'm going to lock this issue because it has been closed for _30 days_ โณ. This helps our maintainers find and focus on the active issues.
If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks!
Most helpful comment
I know it's closed, but to help someone searching on google, I've deleted a vpc and created a new default vpc and I got this problem, to solve this, I go to Amazon RDS > Subnet groups > and I deleted the subnet group, and worked