DEV Community

Bhaskar Sharma
Bhaskar Sharma

Posted on

πŸš€ Day 11 of My DevOps Journey: Terraform β€” Infrastructure as Code (IaC) ☁️

Hello dev.to community! πŸ‘‹

Yesterday, I explored Docker Compose β€” a tool that simplifies managing multi-container apps. Today, I’m stepping into the world of Infrastructure as Code (IaC) with Terraform.

πŸ”Ή Why IaC Matters
Traditionally, provisioning infrastructure meant manual clicks on cloud dashboards β€” slow, error-prone, and hard to reproduce.
With IaC tools like Terraform, infrastructure is:

Automated β†’ Write once, provision anywhere.

Version-controlled β†’ Store infra code in Git, track changes like software.

Consistent & Repeatable β†’ No more β€œit works on my cloud” issues.

🧠 Core Terraform Concepts I’m Learning

Providers β†’ Plugins to interact with cloud (AWS, Azure, GCP).

Resources β†’ Define infrastructure (VMs, networks, S3 buckets, etc.).

State File β†’ Tracks the current infrastructure state.

Plan & Apply β†’ Preview changes before applying them.

πŸ”§ Example: Create an AWS EC2 Instance

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

resource "aws_instance" "my_ec2" {
ami = "ami-08e5424edfe926b43"
instance_type = "t2.micro"
tags = {
Name = "DevOps-Instance"
}
}

πŸ‘‰ Run:

terraform init # Initialize provider plugins

terraform plan # Preview execution plan

terraform apply # Create infrastructure πŸš€

πŸ› οΈ Mini Use Cases in DevOps

Spin up test environments on-demand.

Automate cloud infrastructure for CI/CD pipelines.

Version-control infra changes (review infra via pull requests).

Reduce cloud cost by managing lifecycle (create/destroy easily).

⚑ Pro Tips

Always use terraform.tfvars for secrets/variables.

Store state file remotely (S3 + DynamoDB for AWS).

Use modules to reuse infrastructure code.

Combine with Ansible later for config management.

πŸ§ͺ Hands-on Mini-Lab (Try this!)
1️⃣ Install Terraform.
2️⃣ Write a Terraform config to provision an EC2 instance.
3️⃣ Run terraform init, plan, apply.
4️⃣ Destroy resources with terraform destroy (save money πŸ’Έ).

🎯 Key Takeaway
Terraform brings the power of code to infrastructure β€” making it automated, versioned, and consistent. A must-have skill in every DevOps toolkit.

πŸ”œ Tomorrow (Day 12)
I’ll explore Ansible β€” automating configuration management and deployments. πŸ”§

πŸ”– #Terraform #DevOps #IaC #Cloud #Automation #SRE #InfrastructureAsCode #AWS #CloudNative

Top comments (0)