Photo by Nikolay Tarashchenko on Unsplash

My Experiment with Terraform & AWS

Vimal Prakash J
3 min readJul 16, 2020

--

One of the many things that I’m trying to do during these lock-down times is to complete some of my pending learning projects, personal targets and enjoy the family time. Besides, that is all we have to keep us moving.

On that, “Terraform with AWS” has been my long pending project to complete. After exploring quite a bit of AWS world, Terraform was my next battle. Terraform had always excited me with its declarative style of code.

Why did I not choose CloudFormation over AWS ? Simply put CloudFormation is AWS native but Terraform is NOT and open source. Its super portable and hence opens many IaaC opportunities for various platforms. A nice article on it: https://cloudonaut.io/cloudformation-vs-terraform/

So what did I do this time ? I created a simple (very simple, in fact) multi-tier AWS infrastructure involving components such as: EC2, VPC, Security Groups, Subnets, Route Tables, Internet Gateway, and NAT gateway, by not touching the console but all by IaaC. Exciting Isn’t it ? :)

To do the coding, I used the Microsoft’s Visual Studio Code with Terraform plugin. VS Code, is simply the best free IDE and highly recommended.

To achieve this task, I created 5 Terraform files:

  1. vpc.tf : To create all the network related objects, VPC, Security Group, Subnets, Internet Gateway, NAT gateway & route tables.
  2. variables.tf : All my variables goes in here, as a separate file so that it can be modified whenever needed and create new infrastructure.
  3. securitygroup.tf : For creating all the security groups.
  4. servers.tf : Finally, the file to create my actual servers and its placement.
  5. terraform.tfvars : My access & secret-key, which is kept secret :D

Creating all of these objects, is as easy as hitting enter once (of-course if they had no errors and I had many :P)

And after all the testing and experimenting, removing them to avoid any unnecessary billing is again an “Enter” away.

Behind the scenes: Lot of errors, lot of reading from videos\articles and at the end it was super fun. What did I learn out of this:

  1. Obviously Terraform, although I went through the theory part of it much earlier but such experiments gives the real hands-on confidence.
  2. AWS. Why AWS ? By not going to the console, Terraform makes you to think and code all that you need for things to work. It is not as simpler as entering values in the AWS Console when asks for it. So this approach, strengthens the existing AWS knowledge.
  3. Git : With this project, I am starting to put all of my work in Git. To document all of it in a single place. I’m planning to add in all of my old works also. This gives me an opportunity to have regular hands-on in Git.

I leave some articles and my GitHub repo for reference.

My GitHub Repo : https://github.com/vmalj/workfiles/tree/master/Terraform/Multi-Tier-AWS

Articles : https://learn.hashicorp.com/terraform#getting-started

Happy Learning & Stay home safe. “This Too Shall Pass

--

--

Vimal Prakash J

DevOps, Cloud, Learning Projects, Technology and everything that is worth sharing. || linkedin.com/in/vmalj