VPCIdNotSpecified: No default VPC for this user error when doing terraform apply

Viewed 1823

Terraform newbie here.

I am using the Terraform in Action book here. When I run the terraform apply, I get a VPCIdNotSpecified: No default VPC for this user. GroupName is only supported for EC2-Classic and default VPC error. I have installed both the AWS CLI and configured my AWS credentials using aws configure. My AWS credentials are present in %UserProfile%\.aws\credentials file.

What am I missing?

main.tf

provider "aws" {
    region = "us-west-2"
}
resource "aws_instance" "helloworld" {
    ami = "ami-09dd2e08d601bff67"
    instance_type = "t2.micro"
    tags = {
        Name = "HelloWorld"
    }
}

Error stackTrace:

aws_instance.helloworld: Creating...
╷
│ Error: Error launching source instance: VPCIdNotSpecified: No default VPC for this user. GroupName is only supported for EC2-Classic and default VPC.
│       status code: 400, request id: 1e0911db-300b-4c00-aea1-dad588bbe40e
│
│   with aws_instance.helloworld,
│   on main.tf line 4, in resource "aws_instance" "helloworld":
│    4: resource "aws_instance" "helloworld" {
│
1 Answers

it seems like you don't have a default VPC in the us-west-2 region.

Since you have mentioned you are just starting off with Terraform; I would highly recommend, referring to official Terraform documentation when you want to use a particular resource/module/provider.

In this case, for Resource: aws_instance, you can see what all attributes are supported.

If I were you I would first check if there's a default VPC in the aforementioned region. It's highly likely there's none. If I know the VPC subnet ID then I would simply pass on that value to the subnet_id attribute and Terraform will ensure that my instance will come up in the correct network.

Related