β± Duration: 5 Hours
π Learning Objectives
- Understand what Infrastructure as Code is
- Learn the benefits of IaC over manual provisioning
- Introduction to Terraform and its ecosystem
- Install and configure Terraform
π Core Concepts (2 Hours)
What is Infrastructure as Code?
Infrastructure as Code (IaC) is the practice of managing and provisioning infrastructure through machine-readable configuration files rather than manual processes.
- Declarative: Define what you want, not how to create it
- Version Controlled: Track changes like application code
- Reproducible: Same config = same infrastructure
- Automated: No manual clicking in consoles
Manual vs IaC Approach
Manual Process:
βββββββββββββββββββββββββββββββββββββββ
β 1. Login to AWS Console β
β 2. Click EC2 β Launch Instance β
β 3. Select AMI, instance type β
β 4. Configure security groups β
β 5. Add storage, tags β
β 6. Launch and wait... β
β [Time: 10-15 min, Error-prone] β
βββββββββββββββββββββββββββββββββββββββ
IaC Process (Terraform):
βββββββββββββββββββββββββββββββββββββββ
β 1. Write configuration file β
β 2. Run: terraform apply β
β 3. Done! β
β [Time: 2 min, Reproducible] β
βββββββββββββββββββββββββββββββββββββββBenefits of IaC
β Consistency - Same environment every time
β Speed - Deploy infrastructure in minutes
β Documentation - Config files document your infra
β Version Control- Git history of all changes
β Reusability - Use modules for common patterns
β Cost Control - Easy to destroy and recreate
β Collaboration - Team reviews infrastructure changesIaC Tools Comparison
Tool Language Cloud Support
βββββββββββββββββββββββββββββββββββββββββββββ
Terraform HCL Multi-cloud
CloudFormation YAML/JSON AWS only
Pulumi Python/JS/etc Multi-cloud
Ansible YAML Multi-cloud
ARM Templates JSON Azure only
Why Terraform?
β’ Cloud agnostic (AWS, Azure, GCP, etc.)
β’ Large community and modules
β’ Declarative and readable syntax
β’ State management built-inTerraform Architecture
ββββββββββββββββββββββββββββββββββββββββββββ
β Terraform Core β
β (Parses config, builds resource graph) β
βββββββββββββββββββ¬βββββββββββββββββββββββββ
β
βββββββββββββββΌββββββββββββββ
βΌ βΌ βΌ
βββββββββ βββββββββ βββββββββ
β AWS β β Azure β β GCP β
βProviderβ βProviderβ βProviderβ
βββββ¬ββββ βββββ¬ββββ βββββ¬ββββ
β β β
βΌ βΌ βΌ
AWS API Azure API GCP API㪠Hands-on Lab (2.5 Hours)
Lab 1: Install Terraform
# On Ubuntu/Debian
wget -O- https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list
sudo apt update && sudo apt install terraform
# On macOS
brew tap hashicorp/tap
brew install hashicorp/tap/terraform
# Verify installation
terraform version
terraform -helpLab 2: Configure AWS Credentials
# Install AWS CLI if not installed
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install
# Configure credentials
aws configure
# Enter:
# - AWS Access Key ID
# - AWS Secret Access Key
# - Default region (e.g., us-east-1)
# - Default output format (json)
# Verify configuration
aws sts get-caller-identityLab 3: First Terraform File
# Create project directory
mkdir -p ~/terraform-labs/lab1
cd ~/terraform-labs/lab1
# Create main.tf
cat > main.tf << 'EOF'
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 5.0"
}
}
}
provider "aws" {
region = "us-east-1"
}
# This just outputs a message - no resources created yet
output "hello" {
value = "Hello from Terraform!"
}
EOF
# Initialize Terraform
terraform init
# See what Terraform will do
terraform plan
# Apply (creates nothing yet, just outputs)
terraform applyβ Day 1 Checklist
- Understand what IaC is and its benefits
- Know why Terraform is popular
- Terraform installed and working
- AWS CLI configured with credentials
- Created first Terraform configuration