Day 15 - Cross Region VPC Peering with Terraform
There’s something powerful about watching two completely separate networks start talking to each other… quietly, privately, without the internet even noticing.
Today’s build was exactly that.
I created two VPCs in different AWS regions and connected them using VPC peering, allowing EC2 instances to communicate using private IP addresses.
Architecture
Here is the architecture I implemented:
Simple Flow
User → SSH → EC2 (Primary VPC) → Private Network → EC2 (Secondary VPC)
What I Built
I created:
- Two VPCs in different regions
- One public subnet in each VPC
- Internet gateways for both VPCs
- Route tables with peering routes
- VPC peering connection (cross region)
- Two EC2 instances with Apache installed
- Security groups allowing SSH, ICMP, and TCP
Step 1: Initialize Terraform
I started by initializing Terraform.
terraform init
- Terminal showing
Terraform has been successfully initialized
Step 2: Review Execution Plan
terraform plan
This step shows everything Terraform is going to create.
- Plan output showing VPCs, EC2, peering, routes
Step 3: Deploy Infrastructure
terraform apply
After confirming, Terraform created everything across both regions.
- Final line:
Apply complete! Resources: X added
Step 4: Verify VPCs in AWS Console
- Primary VPC (us-east-1)
- Secondary VPC (us-west-2)
Step 5: Verify VPC Peering
- Peering connection with Status = Active
This is the bridge between both worlds.
Step 6: Verify Route Tables
This is where things usually break if missed.
Each VPC must know how to reach the other.
Primary route table:
- Destination:
10.1.0.0/16 - Target: Peering connection
Secondary route table:
- Destination:
10.0.0.0/16 - Target: Peering connection
Step 7: Verify EC2 Instances
Step 8: Test Connectivity (The Real Moment)
SSH into the Secondary instance and do a Ping and HTTP test to Primary Instance
SSH into the Primary instance and do a Ping and HTTP test to Secondary Instance
Challenges I Faced
- Understanding that peering alone is not enough
- Remembering to update route tables on both sides
- Managing resources across two regions using provider aliases
- Handling SSH keys separately per region
Security Note
Instead of opening SSH to the world:
0.0.0.0/0
I restricted access to my IP:
108.227.216.109/32
Small step. Big difference.
Cost Awareness
Even small setups whisper bills in the background.
This project includes:
- EC2 instances
- Cross region data transfer
- VPC resources
So I cleaned up after testing:
terraform destroy
- Destroy complete message
Key Learnings
- VPC peering enables private communication across regions
- CIDR blocks must not overlap
- Route tables control the actual traffic flow
- Security groups must allow cross VPC communication
- Terraform provider aliases enable multi region deployments
Final Thought
Today wasn’t just about connecting two VPCs.
It was about understanding how networks think.
Not everything that is connected, can communicate.
Not everything that communicates, is visible.
And somewhere between routes, rules, and packets , clarity begins.
Comments
Post a Comment