Terraform Basics for AWS Infrastructure as Code
In this video, you will learn how to manage your AWS infrastructure using Terraform to ensure consistent and repeatable cloud deployments.
What this guide covers
You will learn how to replace manual AWS console deployments with Terraform, defining your cloud infrastructure as code to enforce consistency and reduce errors.
When to use it
- Deploying a new EC2 instance or other AWS resource repeatedly without manual clicks
- Synchronizing infrastructure changes across a team without configuration drift
- Troubleshooting intermittent production issues caused by undocumented manual changes
- Transitioning from browser-based AWS setup to automated, auditable infrastructure
The move, step by step
- Install Terraform
Download and install Terraform from terraform.io/downloads. Verify with:
terraform version
- Initialize your Terraform project
Create a directory and inside it a file ending in.tf(e.g.,main.tf). Run:
terraform init
This sets up backend and provider plugins.
- Write your resource block
Define your AWS resource in HCL inside the.tffile. Example EC2 instance:
resource "aws_instance" "web" {
ami = "ami-0c55b159cbfafe1f0"
instance_type = "t2.micro"
}
-
Configure AWS credentials
Set your AWS credentials using environment variables or AWS CLI config to allow Terraform access (see Terraform AWS Provider docs). -
Plan your changes
Preview what Terraform will do before applying:
terraform plan
- Apply your configuration
Deploy resources as described in your.tffiles:
terraform apply
Confirm with yes when prompted.
- Manage incremental changes
Edit your.tffiles to update infrastructure. Runterraform planandterraform applyagain to sync those changes automatically without manual console edits.
Example
Input file main.tf:
resource "aws_instance" "web" {
ami = "ami-0c55b159cbfafe1f0"
instance_type = "t2.micro"
}
Run commands:
terraform init
terraform plan
terraform apply
Expected output snippet:
Apply complete! Resources: 1 added, 0 changed, 0 destroyed.
An EC2 instance is now created exactly as defined, replacing manual AWS console clicks.
Common mistakes
- Mistake: Not running
terraform initbeforeapply→ Fix: Always initialize the directory first to install necessary plugins. - Mistake: Changing infrastructure manually in AWS console after Terraform deploy → Fix: Avoid manual changes; always update
.tffiles instead. - Mistake: Omitting AWS credentials setup → Fix: Configure
AWS_ACCESS_KEY_IDandAWS_SECRET_ACCESS_KEYor use AWS CLI profiles. - Mistake: Applying without review → Fix: Always run
terraform planto preview changes before applying. - Mistake: Using hardcoded AMI IDs without updates → Fix: Track regional AMI changes or use data sources to get latest AMIs.
Next step
Write a simple Terraform file defining a new S3 bucket or EC2 instance and deploy it using terraform init, terraform plan, and terraform apply. Then come back and try the next move from the video.
Pick the smallest version of this guide and try it in your tool of choice in the next 20 minutes.
Get the next AI/career guide in your inbox
One short, practical guide on AI tools, cloud, and the modern career stack. No fluff.