Bitzu

Terraform Associate 004 ยท State and backends

The local backend

Default terraform.tfstate in the working directory, backup file, limits for teams, path argument (6a).

Key points

  • With no backend block, Terraform uses the local backend: state lives in terraform.tfstate in the root module directory, and a backup copy is written when new state is saved.
  • The optional path argument moves the file.
  • It works for one person but gives a team no shared state.

Source: https://developer.hashicorp.com/terraform/language/backend/local

Practice questions

Single choice

You run terraform apply in a fresh directory that has no backend block. Where does Terraform store the state?

  1. In a file named terraform.tfstate in the root module directory
  2. In an HCP Terraform workspace created automatically
  3. In a hidden .terraform/state.json file only
  4. In memory only, discarded after the run finishes
Show answer

Answer: A. In a file named terraform.tfstate in the root module directory

Without a backend block the local backend is used, writing terraform.tfstate in the working (root module) directory. The other places require explicit configuration.

Select all that apply

Which statements about the local backend are correct?

  1. Its default state file is terraform.tfstate relative to the root module
  2. A path argument can point it at a different state file location
  3. It writes a backup file when it saves new state
  4. It keeps state in an object storage bucket by default
  5. It requires an organization name to be set
Show answer

Answer: A. Its default state file is terraform.tfstate relative to the root module, B. A path argument can point it at a different state file location, C. It writes a backup file when it saves new state

Default path, the path argument and backups on write are all true. It does not use object storage, and it needs no organization name (that is the remote/cloud style).

True or false

True or false: because the local backend is the default, you must declare backend "local" {} in your configuration for state to be written to disk.

Show answer

Answer: False

False. The local backend is used implicitly when no backend block exists; declaring it is only needed to set options such as path.

Practice 8 questions on this topic in Bitzu

Short lessons, instant explanations and spaced review of what you get wrong. Free on iOS and Android.

Download on the App StoreGet it on Google Play

More Terraform Associate 004 topics in this module