My Journey into IAC (Infrastructure as Code) with Terraform

Hello everyone! Today, I want to share a personal learning journey—how I got started with Infrastructure as Code (IaC) using Terraform.

It all began when I came across a video by Shubham Londhe, where he demonstrated how to build a multi-tier setup using Terraform. Inspired by that, I decided to try building it myself. It took me approximately 3–4 days to complete, and it was far from smooth—but that’s where the real learning happened.


Initial Struggles

In the beginning, I was writing everything in a single main.tf file—every resource, every configuration. It worked to an extent, but I quickly realized this approach wasn't scalable.

Then I learned about Terraform modules. But honestly, at first, I couldn’t implement them properly. I got stuck, took a short break, and almost gave up—but then I came back with a fresh mindset.


Hosting a Static Website on S3

Instead of jumping back to the full setup, I decided to focus on something smaller and more specific: Static website hosting on S3.

Here’s what I did:

  • Applied proper provider blocks

  • Configured ACL settings

  • Managed index.html and error.html

  • Set up the bucket policy for public access

This small success gave me confidence again.


Learning Modules the Right Way

After the S3 success, I revisited modules. This time I created:

I restructured my main.tf to call these modules properly and placed module definitions in a clean directory structure. Finally, it started to make sense!


The Multi-Environment Challenge

Next, I aimed to create three environments:

  • Dev: 1 EC2 (Ubuntu, t2.micro) + 1 S3 Bucket

  • Staging: 2 EC2s (Amazon Linux, t2.medium)

  • Production: Similar to staging, more robust setup

But here’s the issue: environment variables were not exporting correctly. Even after several attempts, this part gave me a hard time. I created a new code base from scratch, and now it’s working partially—but I’m still debugging and learning.


Key Learnings

  • Don’t write everything in main.tfmodularize!

  • Break big problems into small deployable parts

  • Use simple projects (like static hosting) to build confidence

  • Don't give up when stuck, just pause and return later


This journey is still ongoing, but sharing this is my way of documenting it and maybe helping someone who’s just starting out.

If you're also learning Terraform or DevOps, feel free to connect—let’s grow together! 🌱

0
Subscribe to my newsletter

Read articles from Taranpreet Batra directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Taranpreet Batra
Taranpreet Batra