For system, network and cloud administrators
Sometimes, when trying to create an AWS EC2 instance in Terraform, you might come across an error similar to:
Error: creating EC2 Instance: VPCIdNotSpecified: No default VPC for this user. GroupName is only supported for EC2-Classic and default VPC.
The error refers to the user not having access to the proper AWS resources declared in the Terraform code. Like trying to access an EC2 instance in the wrong AWS zone region. So, basically Terraform will try to create an EC2 instance of an Ubuntu server using the region, AMI id and instance type provided in the code but it will not find those things thus the error.
To make sure you’re providing the correct info about your AWS resources:
For example:
provider "aws" {
region = "eu-west-2"
}
resource "aws_instance" "ec2" {
ami = "ami-0a6006bac3b9bb8d3"
instance_type = "t2.micro"
}