Build a reusable AWS VPC module.
Move beyond a single EC2 deployment. Design a custom network with public and private subnets, reusable Terraform code, remote state and separate development and production environments.
Explore the architecture ↓Understand what you're building
A small network foundation that can be reused by different environments.
10.20.1.0/24Internet Gateway route
For resources requiring public connectivity10.20.2.0/24Local VPC route only
No direct internet route in this labRoute tables · associations · reusable module
Called by separate dev and prod root configurations
Before you begin
terraform init. The dev and prod environments use different state keys. This project does not create the backend bucket.Project folder structure
terraform-intermediate-vpc/
├── modules/
│ └── vpc/
│ ├── main.tf
│ ├── variables.tf
│ └── outputs.tf
└── environments/
├── dev/
│ ├── backend.tf
│ ├── providers.tf
│ ├── main.tf
│ ├── variables.tf
│ ├── outputs.tf
│ └── terraform.tfvars
└── prod/
└── (same six files, separate values and state key)
Run Terraform from environments/dev or environments/prod. Each is an independent root module.
Explore the Terraform files
Select a file, review the code, and copy it into the matching project path.
Deployment workflow
Open terraform/environments/dev.
Install the AWS provider and configure the S3 backend.
Check syntax and configuration before planning.
Confirm account, region, CIDR ranges and resources.
Deploy only after reviewing proposed changes.
Review the destroy plan before cleanup.
cd terraform/environments/dev terraform init terraform fmt -recursive terraform validate terraform plan -var-file="terraform.tfvars" terraform apply -var-file="terraform.tfvars"
Check the result
- VPC exists with CIDR
10.20.0.0/16. - One public and one private subnet were created.
- Public route table has a default route to the Internet Gateway.
- Private route table has no default internet route.
- State is stored under the intended S3 key.
terraform output terraform plan -destroy -var-file="terraform.tfvars" terraform destroy -var-file="terraform.tfvars"
Destroy dev and prod separately. Destroying the VPC does not delete the S3 backend bucket or its state history.
Quick knowledge check
From reusable networking to automated infrastructure.
The Advanced level adds workload modules, testing, secure authentication, policy checks and a protected CI/CD deployment pipeline.