Terraform 004 cheat sheet: quick reference
Last-minute reference for the HashiCorp Terraform Associate (004). It follows HashiCorp’s eight-objective content list, which publishes no weights, so every objective is fair game.
Exam facts
| Format | Multiple choice, online proctored |
| Duration | 1 hour |
| Questions | Not published |
| Passing score | Not published |
| Price | $70.50 USD plus local taxes and fees |
| Validity | 2 years |
| Terraform version | 1.12, plus HCP Terraform |
| Language | English |
| Free retake | Not included |
HashiCorp’s sample page shows true or false, multiple choice and multiple answer questions; for multiple answer, the prompt says how many to choose.
Objectives at a glance
| # | Objective | Core idea |
|---|---|---|
| 1 | Infrastructure as Code | Declarative, versioned, repeatable, one workflow across platforms |
| 2 | Fundamentals | Providers are plugins; versions pinned in the lock file; state maps config to real objects |
| 3 | Core workflow | init, validate, plan, apply, destroy, fmt |
| 4 | Configuration | Resources, data, variables, types, expressions, dependencies, conditions, sensitive data |
| 5 | Modules | Isolated; inputs in, outputs out; pin versions |
| 6 | State | Local backend, locking, remote backend, drift |
| 7 | Maintain | Import, state commands, TF_LOG |
| 8 | HCP Terraform | Workspaces, projects, runs, policies, integrations |
New in 004 per HashiCorp: 4f dependencies, 4g custom conditions, 4h sensitive data and secrets, 8c workspaces and projects.
Commands
| Command | Remember |
|---|---|
terraform init | Downloads providers and modules, sets up the backend; rerun after adding any of these |
terraform validate | Syntax and internal consistency only |
terraform fmt | Canonical style; -check reports without rewriting |
terraform plan | Proposes changes; -out saves a plan |
terraform apply | Executes; apply a saved plan to run exactly what was reviewed |
terraform destroy | Removes what the configuration and state manage; same as apply with the destroy option |
apply -replace=ADDR | Recreate one resource (use instead of the older taint idea) |
plan or apply -refresh-only | Update state to match reality, no infrastructure change |
terraform state list / show | Read state, change nothing |
terraform force-unlock ID | Release a stale lock, only if nothing else is running |
Plan symbols: plus creates, minus destroys, tilde updates in place, minus plus together replaces.
Configuration rules
resourcecreates and manages;dataonly reads.- Reference data as
data.TYPE.NAME.ATTR, a child module output asmodule.NAME.OUTPUT. - Variable sources, lowest to highest precedence: defaults,
TF_VAR_environment variables,terraform.tfvars,*.auto.tfvars, then-varand-var-fileon the command line. for_eachtakes a map or a set of strings (usetosetfor a list);countties instances to index numbers, so removing a middle item shifts the rest.- Implicit dependency comes from a reference;
depends_onis explicit and only for what no argument expresses. - Custom conditions: variable
validationfor inputs;preconditionandpostconditionin a resource or data source lifecycle block (postcondition can useself); outputprecondition. sensitiveredacts output only and does not keep values out of state or plan files.- Ephemeral values (Terraform 1.10) and write-only arguments (1.11) are not stored in state or plan. HashiCorp’s own page for 4h names Vault-based secrets management, and its list of new topics names ephemeral values and write-only arguments, so know both.
Modules
A module is any folder of .tf files; the directory you run in is the root module. A child cannot read parent variables, locals or resources. The version argument works for registry modules, not for local paths. Pin with ~>: ~> 5.1.0 allows 5.1.x, ~> 5.1 allows up to but not including 6.0. module blocks accept count and for_each.
State and maintenance
- Default is a local
terraform.tfstate; teams use a remote backend through thebackendblock, and changing it meansterraform initand a state migration. - Locking prevents concurrent writes where the backend supports it.
- Drift is real infrastructure differing from state or configuration; plan detects it.
- Import attaches an existing object to a resource address; an
importblock makes it reviewable in a plan. You still write the resource configuration. TF_LOGsets the level (TRACE, DEBUG, INFO, WARN, ERROR);TF_LOG_PATHonly sets the file and does nothing withoutTF_LOG.
HCP Terraform
| Concept | Remember |
|---|---|
| Organization | Top level: teams, projects, registry |
| Project | Groups workspaces for access and settings |
| Workspace | Config source, variables, state and run history for one set of infrastructure (not the same as a CLI workspace) |
| Variable set | Shares values across workspaces |
| Run trigger | A successful run in one workspace queues a run in another |
| Workflows | Version control driven, CLI driven, API driven |
| Policy checks | Run between plan and apply and can block the run |
| Dynamic credentials | Short-lived cloud credentials instead of stored keys |
Common traps
- Believing
validatechecks real cloud values. - Thinking
initis only a once-per-project step. - Assuming
sensitiveprotects state. - Giving a list to
for_eachwithouttoset. - Putting a
versionargument on a local module. - Treating a CLI workspace as an HCP Terraform workspace.
- Setting
TF_LOG_PATHwithoutTF_LOG. - Editing the state file by hand instead of using state commands.
Practise with the 20-question test, then review weak spots in the configuration and state guides.