This repository documents my hands-on learning experience with Terraform and AWS Cloud Infrastructure. I started from absolute basics and progressively built real-world infrastructure automation skills.
- β Automated infrastructure provisioning with code
- β Version-controlled infrastructure
- β Repeatable and consistent deployments
- β Infrastructure lifecycle management
- β Provider configuration (AWS)
- β Resource creation and management
- β Variable types (string, list, map)
- β Map lookups for dynamic configurations
- β Provisioners for server configuration
- β State management
- β Terraform workflow and commands
- β EC2 instance deployment
- β Security group configuration
- β SSH key pair management
- β Data sources (AMI, AZs, VPC, IP ranges) for dynamic config
- β Remote state backend (S3, encrypted)
- β Custom VPC: public/private subnets, IGW, NAT Gateway, route tables
- β Multi-AZ network design
- β Free tier optimization (and knowing what is NOT free tier)
terraform-learning/
βββ 01-terraform-basics/ # Started here: Providers & Basic EC2
βββ 02-variables-and-data-types/ # Learned: Variables, Maps, Dynamic Config
βββ 03-provisioners-nginx-automation/ # Mastered: Provisioners & Nginx automation
β βββ data_source/ # Data sources + S3 remote state backend
βββ 04-aws-vpc-networking/ # Built: Custom VPC, subnets, IGW + NAT Gateway
βββ custom-vpc-nat-gateway/
- Terraform v1.9.8 - Infrastructure as Code
- AWS - Cloud platform (Free Tier)
- AWS CLI v2.32.13 - AWS authentication
- Ubuntu 24.04 LTS - Operating system
- Nginx - Web server
- Bash - Shell scripting
terraform init # Initialize and download providers
terraform fmt # Format code to standard style
terraform validate # Validate configuration syntax
terraform plan # Preview infrastructure changes
terraform plan -out=file # Save plan to file
terraform show # Display current state or plan
terraform apply # Create/update infrastructure
terraform apply "planfile" # Apply saved plan
terraform destroy # Remove all infrastructure
terraform state list # List all resources in state
terraform state show # Show specific resource details
terraform console # Interactive console for testing1. Credential Management
- β Started with hardcoded credentials (security risk)
- β Learned AWS CLI configuration (best practice)
- β Understood credential precedence
2. Variable Usage
- β Initially tried
ami = var.AMIS(type mismatch error) - β
Fixed with map lookup:
ami = var.AMIS[var.AWS_REGION] - β Understood map vs string types
3. Security Groups
- β Used fake security group IDs (would fail)
- β Created security groups in Terraform
- β Understood reference vs creation
4. SSH Key Generation
- β Terraform failed - public key file didn't exist
- β
Generated keys with
ssh-keygen -t rsa -b 4096 -f levelup_key -N "" - β Understood public/private key concepts
5. Connection Blocks
- β Duplicate connection blocks in each provisioner
- β Optimized with single connection at resource level
- β Applied DRY principles
What I Did:
- Configured AWS provider
- Created EC2 instance (t2.micro)
- Used count meta-argument for multiple instances
- Tested plan β apply β destroy workflow
Commands Used:
terraform init
terraform fmt
terraform validate
terraform plan -out=01-basics_plan
terraform show 01-basics_plan
terraform apply "01-basics_plan"
terraform destroyWhat I Did:
- Declared string, list, and map variables
- Implemented regional AMI mapping
- Used lookup function for dynamic AMI selection
- Tested variable overrides via command-line
Commands Used:
terraform plan -var="AWS_REGION=us-west-2"
terraform plan -var="AWS_REGION=us-east-2"
terraform console # Tested var.AMIS, var.AMIS[var.AWS_REGION]What I Did:
- Generated SSH keys (RSA 4096-bit)
- Created security group with SSH and HTTP rules
- Deployed EC2 instance with nginx
- Used file provisioner to upload script
- Used remote-exec provisioner to install nginx
- Verified live web server with curl
Result:
- β Live nginx server deployed successfully
- β Fully automated deployment (90 seconds)
- β Successful SSH connection and provisioning
- β Clean destruction (21 seconds)
What I Did:
- Used 7 data sources (AMI, caller identity, region, AZs, VPC, SG, IP ranges)
- Replaced hardcoded AMIs with dynamic
aws_amilookup - Used
slice()to stay within the 60-rule/SG limit - Migrated state to an encrypted S3 backend (
tf-state-learn-001)
Result:
- β Zero hardcoded values in the configuration
- β Remote state in S3 (encrypted, versioned)
What I Did:
- Built a custom VPC (
10.0.0.0/16) with 3 public + 3 private subnets across 3 AZs - Created Internet Gateway, NAT Gateway + Elastic IP, and public/private route tables
- Deployed an EC2 instance into a public subnet with a security group
Result:
- β 21 resources, full multi-AZ network foundation
β οΈ NAT Gateway is not free tier β see Cost & Security Notes below
Read this before running
04β it can generate real charges.
Cost
01β03stay within the AWS Free Tier (t2.micro, default networking).04is NOT free tier. A NAT Gateway costs$0.045/hr ($32/month) plus data-processing charges, and bills even while idle. The Elastic IP is free only while attached to a running NAT Gateway.- Always run
terraform destroywhen you finish a04session, and set a billing/budget alert.
Security (learning-only shortcuts)
- Security groups in
03and04allow SSH (22) β and HTTP/HTTPS β from0.0.0.0/0. This is fine for short-lived labs but is not safe for anything real. - For real use: restrict port 22 to your own IP (
<your-ip>/32) or use AWS SSM Session Manager (no open SSH port at all). - The S3 backend uses encryption but no state locking β solo use only; add DynamoDB (or TF β₯1.10
use_lockfile) for team use.
Total Learning Time: 4+ days
Projects Completed: 5
Infrastructure Deployments: 7+
Lines of Terraform Code: ~1,100
AWS Resources Created: 30+
Errors Debugged: 10+
Concepts Mastered: 50+
- β No hardcoded credentials in code
- β AWS CLI for credential management
- β Sensitive variables marked properly
- β SSH private keys never committed
- β State files in .gitignore
- β terraform.tfvars excluded from Git
- Write infrastructure in code files
- Version control your infrastructure
- Automate provisioning and configuration
- Make infrastructure repeatable and consistent
- Multi-cloud support (AWS, Azure, GCP)
- Declarative syntax (describe what you want)
- State management (tracks real infrastructure)
- Large provider ecosystem
- Industry standard for IaC
This knowledge prepares me for:
- DevOps Engineer roles
- Cloud Engineer positions
- Infrastructure Automation
- CI/CD pipeline development
- Multi-cloud deployments
- Top-level sections: 4
- Terraform Files: 17
- Total Lines: ~1,100+
- Documentation: 6 README files
- Scripts: 1 (installNginx.sh)
This is a personal learning repository. Feel free to fork and use for your own learning!
β Star this repo if you're learning Terraform too!
Last Updated: June 2026