A Beginner's Guide to Using AWS with Visual Studio Code for Terraform


If you’re diving into Terraform and wondering, “How do I even connect this thing to AWS using VS Code?” - trust me, I’ve been there. When I started, I didn’t know where to begin. But now that I’ve figured it out, I want to break it down in the simplest way possible so you can get up and running quickly.
This blog will walk you through how to set up AWS access, install everything you need, and launch your first Terraform-powered infrastructure, all from VS Code.
Before we jump into the setup, here’s a quick look at what Terraform is, especially if you’re just getting started.
Terraform is an open-source tool that lets you build and manage your cloud infrastructure using code. Think of it as writing scripts to create your AWS resources instead of clicking around in the AWS console.
Let’s get started!
What You’ll Need First
Before we begin, make sure you have the following ready:
Visual Studio Code - If you haven’t already, download it here.
An AWS account - Sign up for a free tier AWS account if you don’t have one yet.
Step 1: Create New AWS Access Key & Secret Access Key
First, we need credentials to let Terraform authenticate with AWS. If you already have access keys, you can skip this. If not, here’s how to create new ones:
Login to the AWS Console
In the top-right corner, click your username → Security Credentials.
Scroll down to “Access keys” and click “Create access key”.
Download the credentials or copy them somewhere safe.
You’ll use these keys in the next step to configure your AWS CLI.
Step 2: Install the AWS CLI
The AWS CLI lets Terraform communicate with your AWS account. Here’s how to install it.
On macOS:
- First, install Homebrew (if you don’t have it already):
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
- Then install the AWS CLI:
brew install awscli
- To confirm the installation run:
aws --version
On Windows:
- Download the official AWS CLI MSI installer for Windows (64-bit) and run it to begin installation:
Download AWS CLI MSI Installer
- To confirm, open the command prompt and run:
aws --version
On Linux:
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install
Done? Great — now let’s set it up.
Step 3: Configure the AWS CLI
Once installed, open your terminal and run:
aws configure
You’ll be prompted to enter:
AWS Access Key ID (input the access key from Step 1)
AWS Secret Access Key (input the secret key from Step 1)
Default region name (e.g., us-east-1) (optional)
Output format (e.g., json) (optional)
Done! To confirm it worked:
aws sts get-caller-identity
If this returns your account info, you're good to go.
Step 4: Install Terraform
Next, let’s install Terraform CLI, which is what you’ll use to define infrastructure as code.
On macOS:
brew tap hashicorp/tap
brew install hashicorp/tap/terraform
On Windows:
Get the appropriate Terraform binary for Windows from the official site based on the latest version:
Extract the ZIP
Right-click the ZIP → “Extract All”
Copy the terraform.exe file to a permanent location like:
C:\Program Files\Terraform\
Add Terraform to the system PATH
Press ⊞ Win → search for “Environment Variables”
Click “Edit the system environment variables”
In the System Properties window, click “Environment Variables”
Under “System variables”, find
Path
→ click EditAdd a new entry:
C:\Program Files\Terraform\
Click OK → OK → OK
Verify in Command Prompt or PowerShell:
terraform -v
On Linux:
Download the correct Terraform binary for your Linux distribution from the official site:
Extract the ZIP
unzip terraform_1.7.5_darwin_arm64.zip
You’ll now have a terraform binary in your current folder.
- Move it to a directory in your system PATH
sudo mv terraform /usr/local/bin/
- Verify it:
terraform -v
It should show you the version — done!
Step 5: Set Up VS Code with Helpful Extensions
Open VS Code and go to the Extensions tab. Search and install:
Terraform by HashiCorp (for syntax highlighting, auto-complete)
AWS Toolkit by Amazon Web Services (lets you browse AWS resources inside VS Code)
AWS CLI Commands (optional, but helpful in quickly accessing the AWS cli info and docs from VS code)
These tools will make your Terraform development smoother and more visual.
Step 6: Create Your First Terraform Project
Let’s build something simple — an S3 bucket!
- Open VS Code Terminal by selecting View > Terminal from the menu bar or by pressing ⌃` keyboard shortcut.
mkdir terraform-aws-lab && cd terraform-aws-lab
- Create a file called main.tf:
provider "aws" {
region = "us-east-1"
}
resource "aws_s3_bucket" "lab" {
bucket = "trove23325-bucket" #should be unique
tags = {
Name = "my s3 bucket"
Environment = "Dev"
}
}
- Now initialize the Terraform working directory:
terraform init
- Preview changes:
terraform plan
- Apply the changes:
terraform apply -auto-approve
—> Bonus: Managing Multiple AWS Accounts
If you use more than one AWS account (like one for personal and one for work), here’s a handy trick:
- Set up a named profile:
aws configure --profile work-account
- In Terraform, reference it like this:
provider "aws" {
region = "us-west-2"
profile = "work-account"
}
Now you can switch between accounts easily.
You’re All Set!
Congrats! You just connected AWS to VS Code and created your first resource using Terraform.
Now that everything’s set up, you can start exploring more advanced infrastructure like EC2, RDS, VPCs, and IAM, all through code.
Let me know in the comments if you’d like a follow-up post on automating something fun with Terraform, or drop your questions if you get stuck.
Happy Terraforming!
Subscribe to my newsletter
Read articles from Divyalakshmi G directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
