Terraform guides
Plain-English guides to Terraform, from what it is to state, modules and the Terraform Associate exam. Every guide uses real commands and real plan output, and most show the same thing running in a Planfile Lab.
Start here
- What is TerraformWhat Terraform is, what it is used for and how it works: HCL, providers, state and the init, plan, apply workflow on AWS, Azure and GCP, with a real example.
- Terraform tutorialA step-by-step Terraform tutorial for beginners: install Terraform, write an AWS S3 config, then init, plan, apply, update, replace, add variables and destroy.
- Terraform labsHow to practise Terraform hands-on, with or without a cloud: local providers, LocalStack, sandbox accounts, 10 practice exercises and Planfile's 26 Labs.
- Terraform commandsEvery Terraform CLI command you need, grouped and explained with examples: init, plan, apply, state, workspaces, import, console, test and TF_LOG logging.
The core workflow
- terraform initWhat terraform init does, when to run it again, and how -upgrade, -reconfigure, -migrate-state and -backend-config work, with fixes for common init errors.
- terraform planWhat terraform plan does, how to read its symbols (+, ~, -, -/+), why a change forces replacement, and how to save a plan with -out and apply it.
- apply and destroyHow terraform apply and terraform destroy work: approval, saved plans, -auto-approve, -target, partial failures, and how to destroy one specific resource.
- terraform fmt and validateHow terraform fmt formats code (-recursive, -check, -diff) and what terraform validate checks and doesn't, with real errors, CI setup and pre-commit hooks.
Writing configuration
- Terraform providersHow Terraform providers work: required_providers, version constraints, the lock file, configuring and authenticating the AWS provider, aliases and data sources.
- variables and outputsTerraform input variables, types, validation, tfvars and precedence, locals, outputs and the terraform output command (-json, -raw), with copyable HCL.
- for_each and countTerraform for_each vs count with examples: count.index, each.key and each.value, toset(), conditional resources, for expressions and dynamic blocks.
- terraform functionsTerraform built-in functions with examples and results: format, replace, merge, lookup, zipmap, cidrsubnet, templatefile, try, plus terraform console.
- terraform lifecycleEvery Terraform lifecycle argument with examples: create_before_destroy, prevent_destroy, ignore_changes, replace_triggered_by, depends_on and conditions.
- terraform modulesHow Terraform modules work: root vs child modules, file structure, calling a module from a path, registry or Git, versions, outputs and best practices.
State and change
- terraform stateWhat the Terraform state file holds, how to keep it in an S3 backend with locking, force-unlock, and the terraform state list, show, mv and rm commands.
- terraform importHow to import existing resources into Terraform with import blocks and -generate-config-out, the legacy terraform import command, and an S3 bucket example.
- terraform driftWhat Terraform drift is, how terraform plan reports changes made outside Terraform, and how to revert them or keep them with apply -refresh-only.
- moved blockHow Terraform moved blocks rename resources, move them into modules or from count to for_each without destroying them, and how they compare to state mv.
- taint and -replaceWhy terraform taint is deprecated, how to force a resource to be replaced with terraform apply -replace, how untaint works and when Terraform taints on its own.
- Terraform workspacesTerraform workspace commands (new, select, list, show, delete), terraform.workspace, state per workspace, when not to use them, and HCP Terraform workspaces.
The Terraform Associate exam
- Terraform certificationHashiCorp Certified: Terraform Associate (004): exam format, cost, every objective with study links, changes from 003, a 4-week study plan and exam-day tips.
- Practice questions15 free Terraform Associate (004) practice questions with answers and explanations, covering providers, workflow, variables, state and modules. No exam dumps.
Comparisons
- Terraform vs AnsibleTerraform vs Ansible compared: provisioning vs configuration management, state, HCL vs YAML, the same EC2 and nginx task in both, and using them together.
- Terraform vs CloudFormationTerraform vs AWS CloudFormation: multi-cloud vs AWS-only, HCL vs YAML, state files vs stacks, plans vs change sets, drift, cost, and one S3 bucket in both.
- Terraform vs OpenTofuTerraform vs OpenTofu explained: the 2023 licence change and fork, what's compatible, features unique to each, what the BUSL means for you, and how to migrate.
- Pulumi vs TerraformPulumi vs Terraform compared: general-purpose languages vs HCL, state backends, providers, testing, licences, the same S3 bucket in both, and when to pick each.