Master command reference
Commands
Categories are derived from each command’s “Touches” column below.
| Command | Purpose | Key flags | Touches |
|---|---|---|---|
terraform init | Set up the backend, modules, providers, and lock file | -upgrade · -backend=false · -backend-config · -migrate-state · -reconfigure · -force-copy · -input=false | .terraform/, lock file, backend setup |
terraform validate | Check syntax and internal consistency | -json | Reads configuration only read-only |
terraform fmt | Canonical formatting | -check · -recursive · -diff · -write=false | Rewrites whitespace in .tf and .tfvars files |
terraform plan | Propose changes | -out · -refresh-only · -refresh=false · -target · -replace · -destroy · -var · -var-file · -detailed-exitcode · -generate-config-out · -lock-timeout · -parallelism | Reads configuration, state, and infrastructure. Writes nothing. touches stateread-only |
terraform apply | Execute changes | Same as plan, plus -auto-approve, or a plan file as the argument | Writes state and infrastructure writes infrastructuretouches state |
terraform destroy | Destroy everything managed (= apply -destroy) | -target · -auto-approve | Writes state and infrastructure writes infrastructuretouches state |
terraform show | Show state or a saved plan in readable form | -json · [planfile] | Reads read-only |
terraform output | Show root module outputs | -json · -raw NAME | Reads state touches stateread-only |
terraform state list | List resource addresses | [address prefix] · -id=ID | Reads touches stateread-only |
terraform state show | Show one resource's attributes | ADDR | Reads touches stateread-only |
terraform state mv | Change a resource's address | SRC DEST | Writes state touches state |
terraform state rm | Stop tracking a resource (object survives) | ADDR | Writes state touches state |
terraform state pull / push | Raw state download and upload (disaster recovery) | — | push writes statetouches state |
terraform state replace-provider | Change the provider source address recorded in state | FROM TO | Writes state touches state |
terraform import | Adopt an existing object (CLI) | ADDR ID | Writes state immediately touches state |
terraform force-unlock | Clear a stuck lock | LOCK_ID | Backend lock |
terraform console | Evaluate expressions interactively | — | Reads; holds the state lock touches stateread-only |
terraform graph | Dependency graph in DOT format | -type=plan | Reads read-only |
terraform providers | Show provider requirements by module | — | Reads read-only |
terraform providers lock | Add lock-file checksums for other platforms | -platform=OS_ARCH | Lock file |
terraform providers schema | Dump provider schemas | -json | Reads read-only |
terraform get | Download modules only | -update | .terraform/modules/ |
terraform workspace | Manage CLI workspaces (HCP workspaces when a cloud block uses tags) | list · show · new · select [-or-create] · delete [-force] | Backend states touches state |
terraform login / logout | Store or remove an HCP Terraform API token | [hostname] | ~/.terraform.d/credentials.tfrc.json |
terraform version | Show the CLI version and provider versions | -json | — |
terraform taint / untaint | Deprecated. Use -replace. | — | Writes state touches state |
terraform refresh | Deprecated. Equivalent to apply -refresh-only -auto-approve. | — | Writes state touches state |
Environment variables
| Variable | Purpose |
|---|---|
TF_VAR_<name> | Set an input variable in the root module |
TF_LOG | Log level: TRACE, DEBUG, INFO, WARN, ERROR, or JSON |
TF_LOG_PATH | Write logs to a file. Requires a log level to be set as well. |
TF_LOG_CORE / TF_LOG_PROVIDER | Set the log level for core or for providers separately |
TF_WORKSPACE | Select a workspace |
TF_TOKEN_<host_with_underscores> | HCP Terraform or Enterprise API token, for example TF_TOKEN_app_terraform_io |
TF_CLOUD_ORGANIZATION / TF_CLOUD_HOSTNAME | Supply cloud block settings |
TF_PLUGIN_CACHE_DIR | Shared provider download cache |
TF_INPUT=0 | Disable interactive prompts, like -input=false |
TF_CLI_ARGS / TF_CLI_ARGS_<command> | Add default flags to commands, for example TF_CLI_ARGS_plan="-parallelism=5" |
File and directory map
| Path | What it is | Commit it? |
|---|---|---|
*.tf | Configuration | ✓ |
terraform.tfvars, *.auto.tfvars | Automatically loaded variable values. Keep secrets out of them. | ✓ (non-secret values only) |
.terraform.lock.hcl | Provider lock file | ✓ |
.terraform/ | Providers, modules, backend settings | ✗ |
terraform.tfstate, *.backup | Local state | ✗ (never) |
terraform.tfstate.d/ | Local CLI workspace states | ✗ |
*.tfplan (saved plans) | Binary plan files, which can contain secrets | ✗ |
crash.log | Panic diagnostics | ✗ |
~/.terraform.d/credentials.tfrc.json | HCP Terraform API tokens | ✗ (never) |
Items to Verify Against Live Documentation
Before relying on these at work or on exam day, check them against current HashiCorp documentation:
- HCP Terraform plan-tier feature availability (Module 8)
- The full HCP Terraform variable precedence order (Lesson 8.4)
identityin import blocks, new in 1.12 (Lesson 7.1)- The minimum Vault provider version for ephemeral and write-only support, which Lab 4D checks directly
- Current proctoring vendor and system requirements (Exam-Day Guide)