Level Up In Tech (LUIT) - Terraform Learning Project
This project teaches Infrastructure as Code (IaC) using Terraform to deploy an Apache web server with automated snapshot backups and disaster recovery capabilities.
- ✅ Deploy EC2 instances with Terraform
- ✅ Install and configure Apache web server
- ✅ Create automated EBS snapshots
- ✅ Implement disaster recovery from snapshots
- ✅ Use Terraform variables and conditionals
- ✅ Work with security groups and user data
┌─────────────────────────────────────────────┐
│ Phase 1: Production Server │
│ ┌────────────┐ │
│ │ EC2 + Apache│ → "Welcome LUIT Students!" │
│ └────────────┘ │
│ ↓ │
│ ┌────────────┐ │
│ │ Snapshot │ (Automated Backup) │
│ └────────────┘ │
└─────────────────────────────────────────────┘
┌─────────────────────────────────────────────┐
│ Phase 2: Disaster Recovery │
│ ┌────────────┐ │
│ │ Snapshot │ │
│ └────────────┘ │
│ ↓ │
│ ┌────────────┐ │
│ │ DR Server │ → Restored from snapshot! │
│ └────────────┘ │
└─────────────────────────────────────────────┘
- AWS Account (Free Tier eligible)
- AWS CLI installed and configured
- Terraform installed (v1.0+)
- Basic command line knowledge
macOS:
brew install terraformWindows (Chocolatey):
choco install terraformLinux:
wget https://releases.hashicorp.com/terraform/1.7.0/terraform_1.7.0_linux_amd64.zip
unzip terraform_1.7.0_linux_amd64.zip
sudo mv terraform /usr/local/bin/aws configure
# Enter your:
# - AWS Access Key ID
# - AWS Secret Access Key
# - Default region (e.g., us-east-1)
# - Output format (json)git clone https://github.com/YOUR-USERNAME/luit-terraform-snapshot-lab.git
cd luit-terraform-snapshot-lab# Copy the example file
cp terraform.tfvars.example terraform.tfvars
# Edit with your values
nano terraform.tfvarsFind your AMI ID:
# Amazon Linux 2
aws ec2 describe-images \
--owners amazon \
--filters "Name=name,Values=amzn2-ami-hvm-*-x86_64-gp2" \
--query 'Images[0].ImageId' \
--output text
# Ubuntu 22.04
aws ec2 describe-images \
--owners 099720109477 \
--filters "Name=name,Values=ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-amd64-server-*" \
--query 'Images[0].ImageId' \
--output text# Initialize Terraform
terraform init
# Preview changes
terraform plan
# Deploy (creates production server + snapshots)
terraform apply
# Type "yes" when prompted# Get the URL from output
terraform output apache_url
# Or visit: http://<your-public-ip>You should see: 🎓 Welcome LUIT Students! 🎓
# Check snapshot status
aws ec2 describe-snapshots --owner-ids self \
--query 'Snapshots[*].[SnapshotId,State,Progress]' \
--output table# Enable disaster recovery mode
terraform apply -var="disaster_recovery_mode=true"
# Type "yes"
# Get DR server URL
terraform output dr_apache_url
# Visit the DR URL - same webpage appears!# Disable disaster recovery
terraform apply -var="disaster_recovery_mode=false"
# Type "yes"terraform destroy
# Type "yes"luit-terraform-snapshot-lab/
├── main.tf # EC2 instance and volumes
├── snapshots.tf # Snapshot creation logic
├── restore.tf # Disaster recovery resources
├── variables.tf # Variable definitions
├── outputs.tf # Output values
├── provider.tf # AWS provider configuration
├── terraform.tfvars.example # Example configuration
├── .gitignore # Files to exclude from Git
├── README.md # This file
└── scripts/
├── install_apache.sh # Apache installation script
└── check_snapshots.sh # Snapshot verification script
Modify scripts/install_apache.sh to change the welcome message.
Change snapshot_retention_count in terraform.tfvars to keep more backups.
Research how to copy snapshots to another AWS region for geographic redundancy.
Add CloudWatch alarms to alert when snapshots fail.
- EC2 t3.micro:
$0.01/hour ($7/month) - EBS 20GB volume: ~$2/month
- Snapshots (7 days × 20GB): ~$1/month
- Total: ~$10/month
💡 Tip: Run terraform destroy when not using to avoid charges!
Solution: You're trying to restore before snapshots are created. Run in two stages:
terraform apply(wait 10 minutes)terraform apply -var="disaster_recovery_mode=true"
Solution: Update my_ami in terraform.tfvars with a valid AMI ID for your region.
Solution: Check security group allows HTTP (port 80):
aws ec2 describe-security-groups --group-ids <your-sg-id>Found a bug or have a suggestion? Please open an issue!
MIT License - Feel free to use this for learning!
Created for Level Up In Tech (LUIT) students to learn Terraform and AWS disaster recovery concepts.
Instructor: [Your Name]
Contact: [Your Email/LinkedIn]
If this helped you learn Terraform, give it a star! ⭐