So far in this series, weβve:
- Built Terraform fundamentals
- Created reusable modules
- Managed remote state
- Designed production-ready structure
- Compared workspaces vs environments
Now itβs time to build something real π₯
π A complete AWS VPC using Terraform
π― What Youβll Learn
In this guide:
- What a VPC is
- How to design basic network architecture
- Create VPC using Terraform
- Add subnet and internet gateway
π What is a VPC?
A VPC (Virtual Private Cloud) is:
π Your own isolated network in AWS
It allows you to control:
- IP range
- Subnets
- Routing
- Internet access
ποΈ Architecture Weβll Build
VPC (10.0.0.0/16)
β
βββ Public Subnet (10.0.1.0/24)
β βββ Internet Gateway
π Project Structure
vpc-lab/
main.tf
variables.tf
πΉ Step 1: Provider Configuration
provider "aws" {
region = "ap-southeast-1"
}
πΉ Step 2: Create VPC
resource "aws_vpc" "main" {
cidr_block = "10.0.0.0/16"
tags = {
Name = "terraform-vpc"
}
}
πΉ Step 3: Create Subnet
resource "aws_subnet" "public" {
vpc_id = aws_vpc.main.id
cidr_block = "10.0.1.0/24"
tags = {
Name = "public-subnet"
}
}
πΉ Step 4: Internet Gateway
resource "aws_internet_gateway" "igw" {
vpc_id = aws_vpc.main.id
tags = {
Name = "main-igw"
}
}
πΉ Step 5: Route Table
resource "aws_route_table" "public" {
vpc_id = aws_vpc.main.id
}
πΉ Step 6: Add Internet Route
resource "aws_route" "internet_access" {
route_table_id = aws_route_table.public.id
destination_cidr_block = "0.0.0.0/0"
gateway_id = aws_internet_gateway.igw.id
}
πΉ Step 7: Associate Subnet
resource "aws_route_table_association" "a" {
subnet_id = aws_subnet.public.id
route_table_id = aws_route_table.public.id
}
π Deploy Infrastructure
terraform init
terraform plan
terraform apply
π§ What You Just Built
You now have:
- A VPC
- A public subnet
- Internet access via IGW
- Routing configuration
π This is the foundation of AWS networking.
π‘ DevOps Insight
Almost every AWS architecture starts with:
π VPC β Subnets β Routing
β οΈ Important Note
Always clean up resources:
terraform destroy
π Avoid unnecessary AWS cost.
π― What You Just Learned
- Basic AWS networking
- Terraform resource relationships
- Real infrastructure deployment
π‘ Final Thought
This is no longer theory.
π You are now building real cloud infrastructure.
π Whatβs Next?
Next, we go deeper:
π Build a 3-tier architecture (ALB + EC2 + DB)
π¨βπ» About the Author
Hi, Iβm Ahkar β sharing DevOps, AWS, and Infrastructure knowledge π
Follow for more Terraform content π₯
π Terraform Learning Series
- Part 7: Workspaces vs Environments
- Part 8: VPC Lab (this post)
- Part 9: 3-Tier Architecture π₯
π Follow to continue π
Top comments (0)