Terraform
Declarative infrastructure provisioning with HashiCorp Configuration Language - from first apply to production-ready patterns
Terraform
Terraform is an open-source infrastructure-as-code tool from HashiCorp. You describe cloud and on-premise resources in declarative HCL (HashiCorp Configuration Language) files, and Terraform figures out the API calls needed to make reality match your description.
Why Terraform
| Without IaC | With Terraform |
|---|---|
| Clicks in a console, undocumented changes | Every resource lives in version control |
| "Works on Dave's laptop" infrastructure | Reproducible across staging, prod, disaster recovery |
| Manual drift reconciliation | terraform plan shows drift before you apply |
| Cloud-specific tooling per provider | One workflow across 3,000+ providers (AWS, GCP, Azure, K8s, Datadog...) |
The Core Loop
write HCL → terraform plan → review diff → terraform apply
↓
state fileThe state file is Terraform's memory: it maps your HCL resources to real cloud objects, so the next plan can compute a diff instead of recreating everything.
Learning Path
Read in this order if you're new — each page builds on the previous one.
1. Getting Started
Install, write your first config, run init/plan/apply
2. Core Concepts
Providers, resources, variables, outputs, data sources
3. State Management
Remote backends, locking, state operations, imports
4. Modules
Reusable building blocks, registry, versioning
5. Advanced Patterns
count, for_each, dynamic blocks, expressions, lifecycle, workspaces
6. Best Practices
Project layout, CI/CD, security, testing, drift detection
Terraform vs. Alternatives
| Tool | Language | Approach | When to choose |
|---|---|---|---|
| Terraform | HCL | Declarative | Multi-cloud, mature ecosystem, large community |
| OpenTofu | HCL | Declarative | Drop-in fork under MPL 2.0 (truly open-source) |
| Pulumi | TS/Python/Go | Imperative | You want real programming language abstractions |
| CloudFormation | YAML/JSON | Declarative | AWS-only, want native AWS integration |
| Crossplane | Kubernetes CRDs | Declarative | You already live inside Kubernetes |
| Ansible | YAML | Procedural | Configuration management (what runs on the box) |
Terraform and Ansible solve different problems. Use Terraform to provision infrastructure (VMs, networks, DBs), and Ansible to configure what runs on it (packages, users, app deploys). See Ansible for the other half.