DEV Community

Bhaskar Sharma
Bhaskar Sharma

Posted on

πŸš€ Day 16 of My DevOps Journey: Terraform β€” Automating Infrastructure as Code (IaC) 🌍

Hello dev.to community! πŸ‘‹

Yesterday, I explored GitLab CI β€” a powerful CI/CD tool that brings the full DevOps lifecycle into one platform. Today, I’m diving into Terraform, one of the most popular Infrastructure as Code (IaC) tools that helps you automate and manage cloud resources efficiently.

πŸ”Ή Why Terraform Matters

Instead of manually creating servers, databases, or networks, Terraform lets you define infrastructure in code. This makes infrastructure:

βœ… Reproducible β†’ Same config works across environments
βœ… Scalable β†’ Spin up or tear down infra quickly
βœ… Version-controlled β†’ Track changes in Git
βœ… Cloud-agnostic β†’ Works with AWS, Azure, GCP, Kubernetes, and more

🧠 Core Terraform Concepts

Provider β†’ Plugin that lets Terraform interact with a cloud/service (AWS, Azure, etc.)

Resource β†’ The actual infrastructure component (VM, DB, Load Balancer)

State File β†’ Terraform’s record of what’s deployed (acts as the source of truth)

Plan & Apply β†’ See proposed changes (terraform plan) and execute (terraform apply)

Modules β†’ Reusable templates for standard infra setups

πŸ”§ Example: Simple Terraform Configuration

provider "aws" {
region = "ap-south-1"
}

resource "aws_instance" "my_ec2" {
ami = "ami-12345678"
instance_type = "t2.micro"
}

πŸ‘‰ Run terraform init β†’ terraform plan β†’ terraform apply
Terraform will provision an EC2 instance automatically πŸš€

πŸ› οΈ DevOps Use Cases

Provision cloud infra (VMs, networks, databases, storage)

Automate Kubernetes cluster setup

Manage multi-cloud environments with the same tool

Integrate with CI/CD (GitLab CI, GitHub Actions, Jenkins)

Use alongside Ansible for config management

⚑ Pro Tips

Always use remote state (S3 + DynamoDB for AWS) to collaborate safely

Use variables & outputs to make configs reusable

Organize infra with modules for production-grade setups

Run terraform destroy carefully β€” it deletes infra! ⚠️

πŸ§ͺ Hands-on Mini-Lab (Try this!)

1️⃣ Install Terraform on your machine
2️⃣ Create a main.tf with an AWS provider + EC2 instance
3️⃣ Run terraform init β†’ terraform apply
4️⃣ Verify the EC2 instance in your AWS Console

🎯 Key Takeaway:
Terraform is the backbone of IaC, making infrastructure consistent, automated, and scalable β€” a must-have skill for every DevOps engineer.

πŸ”œ Tomorrow (Day 17):
I’ll explore Ansible β€” automating configuration management and server provisioning. βš™οΈ

πŸ”– #Terraform #DevOps #IaC #Automation #Cloud #SRE

Top comments (0)