This guide walks you through setting up Terraform on WSL Ubuntu so you can provision AWS resources from Windows. By the end, you’ll have Terraform installed, connected to AWS, and you’ll create an S3 bucket as a working example.
The examples in this guide are run on WSL2 Ubuntu on Windows 11 (the existing URL retains Windows 10 for continuity), but they work the same on any Ubuntu system.
Prerequisites
- WSL2 with Ubuntu installed — see How to Install Ubuntu 20.04 or 22.04 in WSL 2 on Windows 10
- AWS CLI v2 installed and configured with credentials — see How to Install AWS CLI v2 on Ubuntu 22.04
- An AWS account with permissions to create S3 buckets (or whatever resource you plan to provision)
Step 1: Install Terraform
Install Terraform from the official HashiCorp apt repository. This lets you update Terraform through apt upgrade in the future.
Install dependencies
sudo apt update && sudo apt install -y gnupg wget lsb-release software-properties-common
Add the HashiCorp GPG key and repository
wget -O - https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list
Install Terraform
sudo apt update && sudo apt install terraform -y
Verify the installation
terraform -version
You should see the installed version number. If you need a specific version later, see How to Upgrade Terraform to a Specific Version.
Step 2: Verify AWS Credentials
Use IAM Identity Center temporary credentials rather than making access keys the default. Follow the SSO CLI setup guide, then select the same profile for Terraform:
aws configure sso --profile dev
aws sso login --profile dev
export AWS_PROFILE=dev
aws sts get-caller-identity
This should return your AWS account ID, user ARN, and user ID. If it fails, confirm the selected profile, login session, and permission-set assignment. The provider uses the selected profile; credentials do not belong in Terraform files.
Step 3: Create a Terraform Configuration
Create a project directory and a Terraform configuration file that defines an S3 bucket:
mkdir ~/terraform-demo && cd ~/terraform-demo
Create main.tf:
nano main.tf
Add this configuration:
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 6.0"
}
}
required_version = ">= 1.0"
}
provider "aws" {
region = "ap-southeast-1"
}
resource "aws_s3_bucket" "demo" {
bucket = "sb-bucket-name-identifier"
tags = {
Name = "Terraform Demo Bucket"
Environment = "dev"
ManagedBy = "terraform"
}
}
# New S3 buckets default to BucketOwnerEnforced: ACLs are disabled.
# Keep access private through policies and Block Public Access.
resource "aws_s3_bucket_public_access_block" "demo_block" {
bucket = aws_s3_bucket.demo.id
block_public_acls = true
block_public_policy = true
ignore_public_acls = true
restrict_public_buckets = true
}
Replace the bucket name with something unique — S3 bucket names are globally unique across all AWS accounts. Change the region to your preferred AWS region.
This small exercise uses local state. Never commit terraform.tfstate, state backups, saved plan files, credentials, or the .terraform/ directory. State can contain sensitive values. Commit the provider lock file (.terraform.lock.hcl) and configuration instead. For team use, configure a separate existing S3 state bucket with restricted access, versioning, encryption, and native locking (use_lockfile = true on a supporting Terraform release). See HashiCorp’s S3 backend documentation. Do not store this demo’s state in the bucket that this same configuration later destroys.
Step 4: Initialize Terraform
terraform init
This downloads the AWS provider plugin and sets up the working directory. You should see “Terraform has been successfully initialized!” in the output.

If you get a timeout error (common on WSL due to DNS issues), set a longer timeout:
export TF_REGISTRY_CLIENT_TIMEOUT=300
terraform init
Step 5: Preview the Changes with Terraform Plan
terraform plan
This shows what Terraform will create without actually making any changes. Review the output to confirm it will create the S3 bucket with the expected settings.

Step 6: Apply the Configuration
terraform apply
Terraform shows the plan again and asks for confirmation. Type yes and press Enter. After a few seconds, you’ll see “Apply complete! Resources: 2 added, 0 changed, 0 destroyed.”

Step 7: Verify the Resource in AWS
Replace the placeholder below with the exact bucket name from main.tf. A successful head-bucket call has no output and exits with status 0:
aws s3api head-bucket --bucket your-unique-bucket-name
You can also check the AWS Console under S3 to see the bucket with the tags you defined.

Step 8: Clean Up
To avoid any charges, destroy the resources you created:
terraform destroy
Type yes when prompted. Terraform will delete the S3 bucket and confirm the destruction.
Conclusion
You now have Terraform configured on WSL Ubuntu and connected to AWS. From here, you can build on this setup to provision EC2 instances, VPCs, databases, and any other AWS resource Terraform supports. For an alternative IaC CLI, see OpenTofu on WSL2 Ubuntu. For designing your network infrastructure, check out How to Design IP Addressing for Amazon VPC and Subnets.

