Terraform
Build, change, and version infrastructure safely and efficiently with HashiCorp Terraform.
Documentation
| Guide | Description |
|---|---|
| Terraform Fundamentals | HCL syntax, providers, resources, variables, state, data sources, exercises |
| Advanced Terraform | Modules, workspaces, remote state, Terragrunt, CI/CD, import, best practices |
| Command Cheat Sheet | 100+ CLI commands, HCL patterns, state operations, backend configuration |
| Exam Prep | HashiCorp Terraform Associate (003) — domains, practice questions, study plan |
| Interview Questions | 40+ questions from beginner to advanced with detailed answers |
Core Concepts
| Concept | Description |
|---|---|
| Provider | Plugin to interact with cloud APIs (AWS, Azure, GCP) |
| Resource | Infrastructure component to manage |
| State | Terraform's record of managed infrastructure |
| Module | Reusable, composable Terraform configuration |
| Plan | Preview changes before applying |
| Apply | Execute planned changes |
Learning Path
- Start with fundamentals — HCL syntax, providers, resources, variables, state
- Move to advanced patterns — modules, workspaces, remote backends, CI/CD
- Keep the cheat sheet handy — 100+ commands at your fingertips
- Prepare for certification — HashiCorp Associate exam domains and practice
- Practice interview questions — 40+ Q&A with detailed explanations
Quick Start
# main.tf — Example AWS EC2 instance
terraform {
required_providers {
aws = { source = "hashicorp/aws", version = "~> 5.0" }
}
}
provider "aws" { region = "us-east-1" }
resource "aws_instance" "web" {
ami = "ami-0c55b159cbfafe1f0"
instance_type = "t3.micro"
tags = { Name = "CloudCaptain-Web" }
}
terraform init # Initialize working directory
terraform plan # Preview changes
terraform apply # Apply changes
terraform destroy # Destroy infrastructure
terraform fmt # Format configuration
terraform validate # Validate configuration
Best Practices
- Use remote state (S3 + DynamoDB for AWS)
- Lock state to prevent concurrent modifications
- Use modules for reusable infrastructure
- Implement workspaces for environment separation
- Version pin providers and modules
- Use terraform-docs for documentation
- Scan with tfsec or checkov for security
External Resources
| Resource | Description |
|---|---|
| Terraform Documentation | Official HashiCorp docs |
| Terraform Registry | Providers, modules, and policies |
| How To Manage Secrets In Terraform | Professional secrets management |
| Reusable EC2 Instances Using Modules | Terraform modules best practices |
Tools & Utilities
| Tool | Description |
|---|---|
| terraformer | Generate tf/json files from existing infrastructure |
| terrascan | Detect compliance and security violations in IaC |
| tfsec | Static analysis for Terraform security |
| checkov | Policy-as-code for cloud infrastructure |
| terraform-docs | Auto-generate documentation from modules |