DEV Community

David J Eddy
David J Eddy

Posted on

6 1

FIX: Terraform + AWS: InvalidVPCNetworkStateFault

While working with Terraform and AWS recently I ran into an error that did not seem to have much information about it. After about a day of research and troubleshooting I was able to solve it.

The Error

Error: Error applying plan:

1 error(s) occurred:

* module.web_app.aws_db_instance.rds: 1 error(s) occurred:

* aws_db_instance.rds: Error creating DB Instance: InvalidVPCNetworkStateFault: Cannot create a db.t2.micro database instance because no subnets exist in availability zones with sufficient capacity for VPC and storage type : gp2 for db.t2.micro. Please first create at least one new subnet; choose from these availability zones: us-west-1c, us-west-1b.

    status code: 400, request id: ea5f04be-8510-4cfc-9bb2-606c0e00d007

The key takeaways here are RDS, subnets, and availability. So I checked the VPC AZ's, the subnets assigned to them, CIDR ranges, etc. At one point I even compared the VPC configuration to a working zone. From what I could tell no differences existed.

The Cause

After some digging around I noticed the default VPC's subnets had been deleted. This causes the VPC and associated AZ subnets to be invalid in the default DB security group. The only way to recreate default subnets in a region is via the CLI, no web console ability for this action.

The Fix

The fix was to go into RDS subnet group configuration (https://us-west-1.console.aws.amazon.com/rds/home?region=us-west-1#db-subnet-groups) and re-assign the new two new default subnets to the RDS group. After that Terraform 'plan' and 'apply' returned to working as expected.

Image of Datadog

Create and maintain end-to-end frontend tests

Learn best practices on creating frontend tests, testing on-premise apps, integrating tests into your CI/CD pipeline, and using Datadog’s testing tunnel.

Download The Guide

Top comments (0)

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more