Master command reference

Commands

Show only commands that27 commands

Categories are derived from each command’s “Touches” column below.

CommandPurposeKey flagsTouches
terraform initSet 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 validateCheck syntax and internal consistency-jsonReads configuration only
read-only
terraform fmtCanonical formatting-check · -recursive · -diff · -write=falseRewrites whitespace in .tf and .tfvars files
terraform planPropose changes-out · -refresh-only · -refresh=false · -target · -replace · -destroy · -var · -var-file · -detailed-exitcode · -generate-config-out · -lock-timeout · -parallelismReads configuration, state, and infrastructure. Writes nothing.
touches stateread-only
terraform applyExecute changesSame as plan, plus -auto-approve, or a plan file as the argumentWrites state and infrastructure
writes infrastructuretouches state
terraform destroyDestroy everything managed (= apply -destroy)-target · -auto-approveWrites state and infrastructure
writes infrastructuretouches state
terraform showShow state or a saved plan in readable form-json · [planfile]Reads
read-only
terraform outputShow root module outputs-json · -raw NAMEReads state
touches stateread-only
terraform state listList resource addresses[address prefix] · -id=IDReads
touches stateread-only
terraform state showShow one resource's attributesADDRReads
touches stateread-only
terraform state mvChange a resource's addressSRC DESTWrites state
touches state
terraform state rmStop tracking a resource (object survives)ADDRWrites state
touches state
terraform state pull / pushRaw state download and upload (disaster recovery)—push writes state
touches state
terraform state replace-providerChange the provider source address recorded in stateFROM TOWrites state
touches state
terraform importAdopt an existing object (CLI)ADDR IDWrites state immediately
touches state
terraform force-unlockClear a stuck lockLOCK_IDBackend lock
terraform consoleEvaluate expressions interactively—Reads; holds the state lock
touches stateread-only
terraform graphDependency graph in DOT format-type=planReads
read-only
terraform providersShow provider requirements by module—Reads
read-only
terraform providers lockAdd lock-file checksums for other platforms-platform=OS_ARCHLock file
terraform providers schemaDump provider schemas-jsonReads
read-only
terraform getDownload modules only-update.terraform/modules/
terraform workspaceManage CLI workspaces (HCP workspaces when a cloud block uses tags)list · show · new · select [-or-create] · delete [-force]Backend states
touches state
terraform login / logoutStore or remove an HCP Terraform API token[hostname]~/.terraform.d/credentials.tfrc.json
terraform versionShow the CLI version and provider versions-json—
terraform taint / untaintDeprecated. Use -replace.—Writes state
touches state
terraform refreshDeprecated. Equivalent to apply -refresh-only -auto-approve.—Writes state
touches state

Environment variables

VariablePurpose
TF_VAR_<name>Set an input variable in the root module
TF_LOGLog level: TRACE, DEBUG, INFO, WARN, ERROR, or JSON
TF_LOG_PATHWrite logs to a file. Requires a log level to be set as well.
TF_LOG_CORE / TF_LOG_PROVIDERSet the log level for core or for providers separately
TF_WORKSPACESelect 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_HOSTNAMESupply cloud block settings
TF_PLUGIN_CACHE_DIRShared provider download cache
TF_INPUT=0Disable 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

PathWhat it isCommit it?
*.tfConfiguration✓
terraform.tfvars, *.auto.tfvarsAutomatically loaded variable values. Keep secrets out of them.✓ (non-secret values only)
.terraform.lock.hclProvider lock file✓
.terraform/Providers, modules, backend settings✗
terraform.tfstate, *.backupLocal state✗ (never)
terraform.tfstate.d/Local CLI workspace states✗
*.tfplan (saved plans)Binary plan files, which can contain secrets✗
crash.logPanic diagnostics✗
~/.terraform.d/credentials.tfrc.jsonHCP 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)
  • identity in 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)