AWS with Terraform (Day 15)

AWS VPC Peering Using Terraform

Today I completed Day 15 of the #30DaysOfAWSTerraform challenge, and this was one of the most meaningful and practical lessons so far:

Building a fully functional AWS VPC Peering setup between two regions using Terraform, protected with routing, security rules, and private connectivity across networks.

As DevOps engineers, we often need multiple VPCs for environment isolation such as dev, staging, and prod, or multi-region deployments for latency reduction and high availability. VPC Peering helps us enable private communication without exposing traffic to the public internet.


What is VPC Peering?

VPC Peering allows private, low-latency, encrypted communication between two VPCs using private IP addresses. It’s useful when deploying:

  • Multi-region microservices

  • Shared services like monitoring, logging, authentication

  • Hybrid cloud or cross-VPC database access

It’s important because it improves:

✔ Security

(no internet traversal, no exposure)

✔ Performance

(low latency internal routing)

✔ Cost

(no NAT Gateway or Transit Gateway required for small scale)


Key Rules to Remember

RuleDescription
CIDR must not overlap    Peering fails if IP ranges clash
Peering is non-transitive    A ←→ B and B ←→ C doesn’t mean A ←→ C
Requires requester & accepter    Both sides must acknowledge connection
Must be routed manually    Add routes in each VPC’s route table
Security groups must allow traffic    Otherwise private communication breaks

What I Built Today

Architecture

  • VPC A → us-east-1 (CIDR 10.0.0.0/16)

  • VPC B → us-west-2 (CIDR 10.1.0.0/16)

  • Public subnet in each VPC (for demo)

  • EC2 instance in each running Nginx using cloud-init

  • Bi-directional VPC peering

  • Private route setup

  • Security groups for SSH, ICMP, HTTP

  • Multi-region provisioning via aliased providers

The result:

I can SSH & curl the private IP of one EC2 from the other across peered VPCs — fully private & secure.


Key Terraform Patterns Learned

ConceptPurpose
Provider Aliasing    Manage multi-region provisioning cleanly
Modules & Variables    Make code reusable and DRY
User-data    Bootstrap EC2 with web server automatically
Route tables per VPC    Enable private connectivity
VPC peering requester + acceptor    Activate peering end-to-end

Troubleshooting Lessons

IssueFix
Security group denies ICMP/HTTP    Permit CIDR range of peer VPC
Peering stuck in pending-acceptance    Create accepter block or enable auto_accept
No connectivity even after peering    Route tables missing CIDR entry
Key pair error    Local filename ≠ AWS key-name
Both instances unreachable    Wrong subnet association of route table

Hands-On Assignments (Highly recommended)

  • Replace IGW routes with private peering routes

  • Add a third VPC and test non-transitive routing

  • Lock SSH to your public IP (zero trust approach)

  • Refactor code into reusable modules


Diagram


Final Thoughts

This project clearly shows why DevOps engineers love Terraform:
Declarative, repeatable, multi-region infrastructure — no UI clicking, no manual configuration, no drift.

VPC Peering is a cornerstone of real distributed system networking.
Today’s work strengthened foundational cloud networking concepts and reinforced the discipline of writing structured, modular Terraform.

Day 15 completed successfully — and yes, everything is completely private and secure now.


Here is my repo link: https://github.com/Mo-Adnan-Mo-Ayyub/Aws-with-Terraform

Here is today's session link: 




Hashtags

#aws #terraform #devops #cloudcomputing #vpcpeering #30DaysOfAWSTerraform #awscommunity #infrastructureascode #multiRegion #cloudnetworking #learninginpublic #devopsengineer #hashicorp #awsdevops #cloudarchitect

Comments

Popular posts from this blog

AWS with Terraform (Day 01)

AWS with Terraform (Day 02)

AWS with Terraform (Day 06)