1
votes

I'm following the PluralSight course "Terraform - Getting Started" and in it they refer to this terraform file module_three.tf which states the following:

I have changed the original value us-east-1 to my selected region eu-west-2...

variable "region" {
  default = "eu-west-2"
}

...and...

#This uses the default VPC.  It WILL NOT delete it on destroy.
resource "aws_default_vpc" "default" {

}

The commands terraform init and terraform plan execute as expected (and as described in the course), but terraform apply produces this output:

aws_default_vpc.default: Creating...

Error: No default VPC found in this region.

How can I determine the default VPC in a given region and how can I specify a default VPC for my region?

Having to ask that question appears to go against the AWS documentation, as in their section Default VPC and default subnets they clearly state:

If you created your AWS account after 2013-12-04, it supports only EC2-VPC. In this case, you have a default VPC in each AWS Region. A default VPC is ready for you to use so that you don't have to create and configure your own VPC. You can immediately start launching Amazon EC2 instances into your default VPC. You can also use services such as Elastic Load Balancing, Amazon RDS, and Amazon EMR in your default VPC.

2
It sounds like either your account was created before 2013-12-04, or at some point the default VPC in your account, in the eu-west-2 region, has been deleted. On that very page you linked to, if you just scroll down a bit, there are instructions for creating the default VPC if it does not already exist.Mark B

2 Answers

1
votes

This is because terraform is not finding any Default VPC in the region. you can add Default VPC as follows

aws ec2 create-default-vpc
-1
votes

Followed these instructions and created a default VPC.

I had assumed the VPC was defined by AWS in a repository style, but it is actually just an entry created in the account's own list of VPCs.