AWS Cloud Automation using Terraform

Context: As cloud infrastructure grows, organizations deploy resources in multiple AWS regions or acounts. These are deployed on a virtual private cloud (VPC), which by default are isolated from each other, making it difficult to establish secure and efficient communication between them. without a proper solution data traffic between VPCs may have to travel over the public internet, and it significantly increases security risk. This creates a challenge for managing multiple environments, particularly when resources need to interact frequently. A simple solution to this problem is VPC peering, where you create a secure communication route between two private clouds across different regions and data can be transfered without going public. Setting up this infrastructure to do so is a really challenging task as you would have to go to each resource on the AWS dashboard and manualy set up each one for thousands of VMs and clouds. Additionally after deploying the EC2 instance you have to install an application for a specific use case. Basically it's extremely time consuming and not a fun way to do it.

Solution I created a Terraform script that can automate this task. Where traditionally it'd take about 20 minutes to set up a secure private cloud network. The script that I created does it in under a minute. In the variables.tf file You can change regions, availability zone, CIDR blocks and Instance type according to your use case. I have also attached a diagram for better understanding. When an instance is deployed, the script automatically starts and remote SSH session from you local machine to the instance over a secure channel where it will automatically execute commands to install applications for that specific instance without you having to touch your keyboard at all.

Challenges I faced some challenges, I was getting some errors that said can't deploy EC2 instance, ami is invalid after applying the Terraform state which SHOULD NOT happen as everything was perfect. It took me an hour to figure out exactly what was wrong. I even tried ChatGPT Tbh and it's of no use. Turns out, I was copying ami (amazon machine image) id from the wrong region. In my code I had setup us-east-2 but on the AWS EC2 dashboard I was on us-east-1. So, different instances, wrong id. But it all worked in the end.

Built With

  • terraform
Share this project:

Updates