In today project I will be doing a VPC peering between two VPCs
but first what is a VPC pering?
VPC peering is a network connection between two VPCs that enables private communication between resource in the VPCs as if they were in the same network.
The following diagram explains how the peering is done and what resources are going to be created.
What did I use to build this environment?
- Visual Studio Code platform
- Terraform
What was built?
- 2 VPCs
- 2 Subnets
- 2 Internet Gateways
- 2 Route Tables
- 2 Security Groups
- 2 EC2 Instances
- 1 Peering Resource
- 1 AWS Key Pairs
First I prepared my Terraform code for the resources needed for this project
I will need those outputs to log into my servers after they are successfully deployed
I used this scripts for my second instance so it can install Nginx during the bootstrap, so I can check later if we can communicate with it after deployment.
Some of the highlights…
Terraform apply
The deployment is done and you can see I’ve got the private IPs of my instances so I can SSH to them later
Before that I will go to the AWS console and check if everything was successfully deployed.
All looks good
Now I will ssh to Instance a in VPC a
To validate the project I must be able to communicate with instance b in VPC b privately using it’s private IP
I will curl the private IP of the instance b and see if it works
and Voilà it’s working, I received the Nginx welcome page (remember that’s why I used the user data script for instance b)