A comprehensive learning repository for Terraform with progressive examples from basic concepts to advanced patterns.
This repository is organized as a progressive learning journey:
-
01-basics/ - Terraform fundamentals
- Provider configuration
- Basic resources
- Variables and outputs
- Local state management
-
02-variables-outputs/ - Advanced variables
- Complex variable types (lists, maps, objects)
- Variable validation
- Local values and computed data
- Advanced output formatting
-
03-data-sources/ - Data sources
- Fetching existing infrastructure data
- External data sources
- System information queries
-
04-conditionals-loops/ - Control flow
- Conditional expressions
- Count and for_each
- Dynamic blocks
-
05-modules/ - Module development
- Creating reusable modules
- Module composition
- Module registry usage
- pre-commit/ - Code quality automation
- Terraform formatting and validation
- Security scanning with tfsec and checkov
- Documentation generation
Real-world infrastructure examples for major cloud providers:
-
aws/ - Amazon Web Services
- VPC with public/private subnets
- EC2 instances with security groups
- Application Load Balancer
- Auto Scaling configuration
-
azure/ - Microsoft Azure
- Virtual Network and subnets
- Virtual Machines with load balancing
- Storage accounts and monitoring
- Resource group management
-
gcp/ - Google Cloud Platform
- VPC networks and firewall rules
- Compute Engine instances
- Cloud Storage integration
- Managed instance groups
- .github/workflows/ - GitHub Actions workflows
- terraform-validate.yml - Code validation and security scanning
- terraform-plan.yml - Pull request planning and commenting
- terraform-deploy.yml - Multi-cloud deployment pipeline
- terraform-drift.yml - Infrastructure drift detection
- See CI/CD Setup Guide for configuration
- Terraform >= 1.0
- pre-commit (optional, for code quality)
-
Clone and explore:
git clone <repo-url> cd terraform-101
-
Start with basics:
cd 01-basics terraform init terraform plan terraform apply -
Set up pre-commit (recommended):
cp pre-commit/.pre-commit-config.yaml .pre-commit-config.yaml pre-commit install
- Follow the numbered order - Each example builds on concepts from previous ones
- Read the README in each directory for specific learning objectives
- Experiment - Modify the examples to see how changes affect behavior
- Use pre-commit - Learn professional development practices
- Check outputs - Understand how Terraform manages state and outputs
- Start small and build complexity gradually
- Always run
terraform planbeforeapply - Understand state management early
- Practice with different variable types
- Learn to read Terraform documentation
- Use
terraform consolefor testing expressions
# Format all Terraform files
terraform fmt -recursive
# Validate configuration
terraform validate
# Show current state
terraform show
# List resources in state
terraform state list
# Interactive console
terraform console