Domain 6 of 8 · Chapter 3 of 4

Configure remote state with the backend block

Unlock the complete study guide + 1,040 practice questions across 16 full exams.

Bundled into the existing HashiCorp Certified: Terraform Associate premium course — no separate purchase.

14-day money-back guarantee — no questions asked.

Included in this chapter:

  • Where Terraform state lives
  • Choosing a backend type
  • Partial configuration: settings at init
  • The cloud block and re-initializing
  • Exam-pattern recognition

Three ways to store Terraform state

AspectDefault localbackend blockcloud block
How it is declaredNo block; the implicit defaultbackend "TYPE" in the terraform blockcloud block in the terraform block
Where state is storedLocal terraform.tfstate fileThe chosen remote store (S3, GCS, azurerm, ...)HCP Terraform or Terraform Enterprise
State lockingNone across machinesYes, on backends that support itYes, plus queued runs
Can reference variablesn/aNo; literals or -backend-configNo; literals only
Change requires terraform initn/aYes; migrate or reconfigureYes; migrate or reconfigure
Mutually exclusive withn/aA cloud blockA backend block

Decision tree

Share state with a team?more than one person or machineDefault local backendterraform.tfstateUse HCP Terraform?managed runs and governancecloud blockremote runs + stateSettings safe to commit?no secrets in the blockbackend blockfull config, all literalbackend blockpartial config at initNoYesYesNoYesNo

Cheat sheet

  • One backend block, nested in the terraform block
  • Built-in backend types for remote state
  • Backend blocks cannot reference variables
  • Partial configuration supplies backend args at init
  • Partial configuration keeps credentials out of code
  • HCP Terraform uses a cloud block, not a backend block
  • Changing the backend requires re-running terraform init
  • Why remote state (vs. default local state)

Unlock with Premium — includes all practice exams and the complete study guide.

Also tested in

References

  1. Backend Configuration
  2. The terraform Block
  3. Remote State
  4. Command: init