Day 1: Introduction to Infrastructure as Code: Exploring Terraform

Welcome to Day 1 of your Terraform learning journey! Today, weβll start from the very beginningβunderstanding what Infrastructure as Code means and why Terraform has become the go-to tool for managing cloud infrastructure.
π€ The Traditional Way: Manual Infrastructure
Imagine you need to set up a web server on AWS. The traditional approach would be
Log into AWS Console
Click through menus to create a VPC
Manually configure security groups
Launch an EC2 instance
Set up storage, networking, etc.
Document everything in a Word doc or spreadsheet
Problems with this approach:
β Time-consuming and error-prone
β Hard to replicate exactly
β No version control
β Difficult to collaborate with team members
β Documentation gets outdated quickly
π‘ Enter Infrastructure as Code (IaC)
Infrastructure as Code is the practice of managing and provisioning infrastructure through code instead of manual processes.
Think of it this way: instead of clicking buttons, you write code that describes what you want, and a tool creates it for you.
Traditional Approach: IaC Approach:
π€ Human π€ Human
| |
| (clicks) | (writes code)
β β
π₯οΈ AWS Console π Configuration File
| |
| (creates) | (reads)
β β
βοΈ Infrastructure π€ IaC Tool (Terraform)
|
| (creates)
β
βοΈ Infrastructure
π· What is Terraform?
Terraform is an open-source Infrastructure as Code tool created by HashiCorp. It allows you to define your infrastructure using a simple, human-readable language called HCL (HashiCorp Configuration Language).
Key Features:
Multi-Cloud Support: Works with AWS, Azure, GCP, and 1000+ providers
Declarative Syntax: You describe WHAT you want, not HOW to create it
State Management: Tracks your infrastructureβs current state
Plan Before Apply: Preview changes before making them
Resource Graph: Understands dependencies between resources
ποΈ How Terraform Works
βββββββββββββββββββββββββββββββββββββββββββββββββββ
β 1. WRITE: Define infrastructure in .tf files β
β β
β resource "aws_instance" "web" { β
β ami = "ami-12345" β
β instance_type = "t2.micro" β
β } β
ββββββββββββββββββββββ¬βββββββββββββββββββββββββββββ
β
β
βββββββββββββββββββββββββββββββββββββββββββββββββββ
β 2. PLAN: Terraform analyzes and shows changes β
β β
β $ terraform plan β
β + aws_instance.web will be created β
ββββββββββββββββββββββ¬βββββββββββββββββββββββββββββ
β
β
βββββββββββββββββββββββββββββββββββββββββββββββββββ
β 3. APPLY: Terraform creates the resources β
β β
β $ terraform apply β
β β aws_instance.web created β
ββββββββββββββββββββββ¬βββββββββββββββββββββββββββββ
β
β
βββββββββββββββββββββββββββββββββββββββββββββββββββ
β 4. STATE: Terraform saves the current state β
β β
β terraform.tfstate (tracks resources) β
βββββββββββββββββββββββββββββββββββββββββββββββββββ
π― The Terraform Workflow
Terraform follows a simple three-step workflow:
1. Write
Define your infrastructure in .tf files using HCL:
resource "aws_instance" "my_server" {
ami = "ami-0c55b159cbfafe1f0"
instance_type = "t2.micro"
tags = {
Name = "MyFirstServer"
}
}
2. Plan
Terraform compares your code with the current state and shows what will change:
$ terraform plan
Terraform will perform the following actions:
# aws_instance.my_server will be created
+ resource "aws_instance" "my_server" {
+ ami = "ami-0c55b159cbfafe1f0"
+ instance_type = "t2.micro"
...
}
Plan: 1 to add, 0 to change, 0 to destroy.
3. Apply
Execute the plan to create/update infrastructure:
$ terraform apply
...aws_instance.my_server: Creating...
aws_instance.my_server: Creation complete after 45s
Apply complete! Resources: 1 added, 0 changed, 0 destroyed.
π Terraform vs Other Tools
| Feature | Terraform | CloudFormation | Ansible |
| Multi-cloud | β Yes | β AWS only | β Yes |
| Agent required | β No | β No | β No |
| Declarative | β Yes | β Yes | β οΈ Mostly |
| State management | β Yes | β Yes | β No |
| Best for | Infrastructure | AWS infra | Configuration |
β¨ Why Learn Terraform?
High Demand: Top skill in DevOps job listings
Multi-Cloud: One tool for all cloud providers
Version Control: Track infrastructure changes like code
Automation: Integrate with CI/CD pipelines
Collaboration: Teams can work together on infrastructure
Reusability: Create modules used across projects
π Real-World Example
Instead of manually creating a web server, you write this:
# main.tf
provider "aws" {
region = "us-east-1"
}
resource "aws_instance" "web_server" {
ami = "ami-0c55b159cbfafe1f0"
instance_type = "t2.micro"
tags = {
Name = "WebServer"
Environment = "Development"
}
}
Then run:
terraform init
# Initializeterraform plan
# Preview changesterraform apply
# Create resources
And Terraform creates everything for you! π
π Key Concepts to Remember
Provider: Plugin that allows Terraform to interact with cloud platforms (AWS, Azure, etc.)
Resource: A component of your infrastructure (EC2 instance, S3 bucket, etc.)
State: Terraformβs knowledge of your infrastructureβs current status
HCL: HashiCorp Configuration Language - Terraformβs syntax
π§ͺ Hands-On Lab: Explore Terraform Basics
Prerequisites
An AWS account (free tier)
A computer with internet access
Lab Steps
Step 1: Create Your AWS Account
Go to https://aws.amazon.com
Click βCreate an AWS Accountβ
Follow the signup process (requires credit card but weβll use free tier)
Verify your email
Step 2: Understand the AWS Free Tier
AWS provides 750 hours/month of t2.micro instances (free for 12 months)
Weβll stay within free tier limits throughout this series
Always remember to destroy resources after practice!
Step 3: Familiarize with AWS Console
Log into AWS Console: https://console.aws.amazon.com
Navigate to EC2 Dashboard
Browse around - notice how many clicks it takes to launch an instance
Donβt create anything yet - just explore
Step 4: Understand the Manual Process Count the steps to manually create an EC2 instance:
Choose AMI (Amazon Machine Image)
Choose Instance Type
Configure Instance Details
Add Storage
Add Tags
Configure Security Group
Review and Launch
Create/Select Key Pair
Thatβs 8+ steps with dozens of options! Tomorrow, weβll do this with just a few lines of code.
Step 5: Reflection Questions Think about these (write down your answers):
How would you recreate this exact setup in another region?
How would you document all the settings you chose?
How would you track who made what changes?
How would you share this setup with your team?
These questions highlight why IaC is essential!
π Summary
Today you learned:
β What Infrastructure as Code is and why it matters
β What Terraform is and how it works
β The three-step Terraform workflow (Write, Plan, Apply)
β Key advantages of using Terraform over manual processes
β Basic Terraform concepts (providers, resources, state)
π Tomorrowβs Preview
Day 2: Installing Terraform & Your First Configuration
Tomorrow, weβll:
Install Terraform on your computer
Set up AWS CLI and credentials
Write your very first Terraform configuration
Create your first AWS resource with code!
π Quiz Yourself
What does IaC stand for?
Name three benefits of using Terraform
What are the three main steps in the Terraform workflow?
What language does Terraform use?
Click for answers
Infrastructure as Code
Multi-cloud support, version control, automation (any three benefits mentioned above)
Write, Plan, Apply
HCL (HashiCorp Configuration Language)
Ready for Day 2? Tomorrow weβll install Terraform and create your first infrastructure!
Happy Learning! π
Thanks For Reading, Follow Me For More
Subscribe youtube channel for the recap videos
Have a great day!..
Remember: The best way to learn is by doing. Make sure you complete the hands-on lab before moving to the next day!



