DEV Community

Cover image for 🌐 Deploying an AWS VPC with Terraform (Hands-On Lab) β€” Part 8
Ahkar Swe
Ahkar Swe

Posted on

🌐 Deploying an AWS VPC with Terraform (Hands-On Lab) β€” Part 8

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
Enter fullscreen mode Exit fullscreen mode

πŸ“ Project Structure

vpc-lab/
  main.tf
  variables.tf
Enter fullscreen mode Exit fullscreen mode

πŸ”Ή Step 1: Provider Configuration

provider "aws" {
  region = "ap-southeast-1"
}
Enter fullscreen mode Exit fullscreen mode

πŸ”Ή Step 2: Create VPC

resource "aws_vpc" "main" {
  cidr_block = "10.0.0.0/16"

  tags = {
    Name = "terraform-vpc"
  }
}
Enter fullscreen mode Exit fullscreen mode

πŸ”Ή 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"
  }
}
Enter fullscreen mode Exit fullscreen mode

πŸ”Ή Step 4: Internet Gateway

resource "aws_internet_gateway" "igw" {
  vpc_id = aws_vpc.main.id

  tags = {
    Name = "main-igw"
  }
}
Enter fullscreen mode Exit fullscreen mode

πŸ”Ή Step 5: Route Table

resource "aws_route_table" "public" {
  vpc_id = aws_vpc.main.id
}
Enter fullscreen mode Exit fullscreen mode

πŸ”Ή 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
}
Enter fullscreen mode Exit fullscreen mode

πŸ”Ή Step 7: Associate Subnet

resource "aws_route_table_association" "a" {
  subnet_id      = aws_subnet.public.id
  route_table_id = aws_route_table.public.id
}
Enter fullscreen mode Exit fullscreen mode

πŸš€ Deploy Infrastructure

terraform init
terraform plan
terraform apply
Enter fullscreen mode Exit fullscreen mode

🧠 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
Enter fullscreen mode Exit fullscreen mode

πŸ‘‰ 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 πŸš€

🌐 https://mindgnite.com

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)