You've heard Terraform is the standard for infrastructure-as-code. You've seen the job postings. But every tutorial starts with 45 minutes of theory before you deploy anything. Let's skip that.
In this guide, you'll deploy a real AWS infrastructure — VPC, EC2 instance, and security groups — in 15 minutes. Working code you can modify, not theory you'll forget.
Prerequisites
- AWS account with IAM credentials configured (
aws configure) - Terraform installed (
brew install terraformor download from terraform.io) - A text editor
That's it. No Kubernetes, no Docker, no CI/CD pipeline. Just Terraform and AWS.
Step 1: Create Your Project
mkdir my-infra && cd my-infra
Create main.tf:
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 5.0"
}
}
}
provider "aws" {
region = "us-east-1"
}
Run:
terraform init
You should see "Terraform has been successfully initialized." If not, check your AWS credentials.
Step 2: Create a VPC
Add to main.tf:
resource "aws_vpc" "main" {
cidr_block = "10.0.0.0/16"
enable_dns_hostnames = true
tags = {
Name = "my-first-vpc"
}
}
resource "aws_subnet" "public" {
vpc_id = aws_vpc.main.id
cidr_block = "10.0.1.0/24"
availability_zone = "us-east-1a"
map_public_ip_on_launch = true
tags = {
Name = "public-subnet"
}
}
resource "aws_internet_gateway" "main" {
vpc_id = aws_vpc.main.id
}
resource "aws_route_table" "public" {
vpc_id = aws_vpc.main.id
route {
cidr_block = "0.0.0.0/0"
gateway_id = aws_internet_gateway.main.id
}
}
resource "aws_route_table_association" "public" {
subnet_id = aws_subnet.public.id
route_table_id = aws_route_table.public.id
}
Run terraform plan to preview. You should see 5 resources to create. The VPC, subnet, internet gateway, route table, and association are the foundation of every AWS deployment.
Step 3: Add a Security Group
resource "aws_security_group" "web" {
name_prefix = "web-"
vpc_id = aws_vpc.main.id
ingress {
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"] # Restrict this to your IP in production
}
ingress {
from_port = 80
to_port = 80
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
}
Step 4: Launch an EC2 Instance
data "aws_ami" "ubuntu" {
most_recent = true
owners = ["099720109477"] # Canonical
filter {
name = "name"
values = ["ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-amd64-server-*"]
}
}
resource "aws_instance" "web" {
ami = data.aws_ami.ubuntu.id
instance_type = "t3.micro"
subnet_id = aws_subnet.public.id
vpc_security_group_ids = [aws_security_group.web.id]
tags = {
Name = "my-first-instance"
}
}
output "instance_public_ip" {
value = aws_instance.web.public_ip
}
Now deploy:
terraform apply
Type yes when prompted. In about 60 seconds, you'll have a running EC2 instance with a public IP address printed to your terminal.
Step 5: Clean Up
When you're done:
terraform destroy
Type yes. Everything gets deleted cleanly. No orphaned resources, no surprise bills.
5 Mistakes Every Terraform Beginner Makes
- Hardcoding region — Use variables (
var.region) so you can deploy to any region - Not using state backends — Local state breaks when you collaborate. Use S3 + DynamoDB
- Ignoring
terraform plan— Always plan before apply. Read the diff - Not tagging resources — Tags make cost tracking and cleanup possible
- Security groups with 0.0.0.0/0 on SSH — Fine for learning, dangerous for production
Going Further
This tutorial covers the basics, but production infrastructure needs:
- Multiple environments (dev/staging/prod) with workspaces or separate state files
- Modules to avoid copy-pasting VPC/subnet configs
- Remote state with locking (S3 + DynamoDB)
- Variables and outputs for reusability
If you want to skip the boilerplate and start with production-ready configs, our Terraform AWS & GCP Starter Templates include VPC, ECS, Cloud Run, RDS, IAM, security groups, and monitoring — all pre-configured and tested. Deploy production infrastructure with terraform apply, not weeks of YAML debugging.
What was the hardest part of learning Terraform for you? Drop a comment below.