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
You run terraform apply in a fresh directory that has no backend block. Where does Terraform store the state?
- In a file named terraform.tfstate in the root module directory
- In an HCP Terraform workspace created automatically
- In a hidden .terraform/state.json file only
- 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.
Which statements about the local backend are correct?
- Its default state file is terraform.tfstate relative to the root module
- A path argument can point it at a different state file location
- It writes a backup file when it saves new state
- It keeps state in an object storage bucket by default
- 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: 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.
