For system, network and cloud administrators

How to fix AWS EC2 error “No default VPC for this user” in Terraform

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.


How to log in AWS using Terraform

Terraform is a wonderful IaaC software. We can login into AWS in a couple of ways:

  • by declaring our AWS credentials (key, secret) inside one of the .tf files (main.tf, for example);
  • by declaring our AWS credentials using the Terraform CLI.


What is Terraform?

Let’s talk about infrastructure. Basically, anything that relates to how we’re setting up and configuring (policies, users, VPCs, storage buckets, etc.) what we want for our technology stack is what it’s called infrastructure. And code written in Terraform is focused on infrastructure. Instead of creating virtual machines, networks and subnets, manually, the developers use Terraform to automatically manage and provision their infrastructure for their application, thus Terraform is frequently used for Infrastructure as a Code (IaaC) on multiple cloud providers (GCP, Azure, AWS, Digital Ocean, etc.) these days.