Skip to content

chinmayto/terraform-aws-networking-vpc-peering

Repository files navigation

VPC Peering Connection between two VPCs in single region using Terraform

Deploying a VPC peering connection between two VPCs in single region using Terraform

A VPC peering connection is a networking connection between two VPCs that enables you to route traffic between them using private IPv4 addresses or IPv6 addresses. Instances in either VPC can communicate with each other as if they are within the same network. You can create a VPC peering connection between your own VPCs, or with a VPC in another AWS account. The VPCs can be in different Regions (also known as an inter-Region VPC peering connection).

Architecture Diagram:

Alt text

Step 1: Create two VPCs with non-overlapping cidrs.

Step 2: Host EC2 instances in each VPC

Step 3: Create a VPC peering connection with routes between two VPCs

Terraform Plan Output:

Plan: 17 to add, 0 to change, 0 to destroy.

Terraform Apply Output:

Apply complete! Resources: 17 added, 0 changed, 0 destroyed.

Outputs:

vpc_a_public_host_IP = "18.212.2.189"
vpc_b_public_host_IP = "3.84.14.236"

VPCs Created with exclusive CIDRs

Alt text

Peering connections with route tables

Alt text

Route Tables showing rote to peering conneciton:

Alt text

Alt text

Instances with private IP in Different CIDrs of VPCs

Alt text

Alt text

Connecting to EC2 in VPC-B from VPC-A

Alt text

Connecting to EC2 in VPC-A from VPC-B

Alt text

EC2 Instance in VPC-A

Alt text

EC2 Instance in VPC-B

Alt text

Terraform Destroy Output:

Plan: 0 to add, 0 to change, 17 to destroy.

Destroy complete! Resources: 17 destroyed.

About

Deploying a VPC peering connection between VPCs

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages