This content originally appeared on DEV Community and was authored by Bhaskar Sharma
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
This content originally appeared on DEV Community and was authored by Bhaskar Sharma