Skip to main content

Command Palette

Search for a command to run...

Building Multi-Region VPC Peering on AWS using Terraform | Mini Project

Updated
4 min read

In this mini project, I explored one of the most important networking concepts in AWS — VPC Peering.

The goal was to establish private communication between multiple VPCs located in different AWS regions using Terraform Infrastructure as Code (IaC).

Instead of creating only two VPCs, I extended the project further by adding a third VPC, subnet, EC2 instance, and all required networking components, then established additional VPC peering connections to understand how multiple VPC networks can communicate securely using private IP addresses.


Architecture Overview

The architecture consists of three independent VPC environments:

Primary VPC (us-east-1)

  • CIDR Block: 10.0.0.0/16

  • Public subnet with EC2 instance

  • Internet Gateway for internet connectivity

Secondary VPC (us-west-2)

  • CIDR Block: 10.1.0.0/16

  • Public subnet with EC2 instance

  • Internet Gateway for internet connectivity

Third VPC

  • Separate CIDR block with its own subnet and EC2 instance

  • Configured with its own route tables, security groups, and internet access

  • Peered with the Primary VPC


VPC Peering Connections Implemented

I configured multiple VPC peering connections:

✅ Primary VPC ↔ Secondary VPC (Cross-region peering)

✅ Primary VPC ↔ Third VPC

Each peering connection was configured with:

  • Proper requester and accepter configuration

  • Non-overlapping CIDR ranges

  • Route table updates for private traffic routing

  • Security group rules allowing communication between VPCs


AWS Resources Created

Networking Resources

  • 3 VPCs

  • 3 Public Subnets

  • 3 Internet Gateways

  • Multiple Route Tables

  • VPC Peering Connections

  • Security Groups with cross-VPC communication rules

Compute Resources

Amazon Linux 2 EC2 instances in each VPC

  • Apache Web Server installation

  • Custom web pages displaying VPC information


Security Configuration

Security groups were configured to allow:

  • SSH access (Port 22) for administration

  • ICMP traffic for ping testing

  • TCP traffic between peered VPC CIDR blocks

  • Outbound internet access through appropriate egress rules


Multi-Region Deployment using Terraform

One of the biggest learnings from this project was managing infrastructure across multiple AWS regions.

Terraform provider aliases were used to manage resources in different regions such as:

  • us-east-1

  • us-west-2

This helped in understanding:

  • Multi-region infrastructure management

  • Cross-region dependencies

  • Region-specific resources such as AMIs and networking components


Project Demonstration

EC2 Instances Across Regions

This verifies successful deployment of compute resources across multiple regions.


VPC Peering Connection

The peering status should be Active, confirming that AWS has successfully established private connectivity between the VPCs.


Connectivity Testing

To validate VPC peering, I tested communication using private IP addresses.

Ping Test

Successful ICMP responses confirm that routing tables, security groups, and peering connections are configured correctly.

HTTP Communication Test

Using curl commands, I verified that Apache web servers hosted in remote VPCs were reachable through private network communication.


Important Concepts Learned

VPC Peering is Non-Transitive

A critical learning from this project is that VPC peering does not support transitive routing.

For example:

VPC A ↔ VPC B
VPC A ↔ VPC C

This does not mean:

VPC B ↔ VPC C

Traffic cannot automatically pass through VPC A to reach another peered VPC. A direct peering connection or another networking solution (such as Transit Gateway) is required.


Cost Considerations

This project creates billable AWS resources:

  • EC2 instances

  • VPC peering data transfer between regions

  • Public IP related charges (if applicable)

Always destroy the resources after testing to avoid unnecessary AWS charges:

terraform destroy

Key Learnings

Through this mini project, I gained hands-on experience with:

✅ Creating VPCs, subnets, and internet gateways using Terraform

✅ Configuring cross-region VPC peering

✅ Managing routing between private networks

✅ Designing security group rules for inter-VPC communication

✅ Deploying EC2 instances across multiple AWS regions

✅ Using Terraform provider aliases for multi-region infrastructure

✅ Testing private connectivity using ping and HTTP requests

✅ Understanding limitations of VPC peering and non-transitive routing


Resources That Helped Me Learn

The official Terraform and AWS documentation, along with YouTube hands-on tutorials, helped me understand VPC networking, peering concepts, and practical implementation using Terraform.


Connect With Me

LinkedIn: https://www.linkedin.com/in/devops-samarjeet/

I will continue documenting my hands-on journey of learning AWS, Terraform, and DevOps through real-world projects and practical implementations.