Describe the local backend
The default backend and where state lives
You run terraform apply in a directory with no backend and no cloud block, and a file named terraform.tfstate appears beside your .tf files. You already know Terraform keeps that state to map your configuration to real resources; what this section adds is exactly where the local backend puts the file, how it locks it, and how workspaces and a few legacy flags move it.
The local backend is a real default, not 'no backend'
A common misread is that a configuration without a backend block has no backend at all. It has one. Terraform uses a backend called local by default, and the local backend type stores state as a local file on disk[1]. More precisely, that backend stores state on the local filesystem, locks that state using system APIs, and performs operations locally[2]. Because it is a genuine backend, you can also write it out explicitly:
terraform {
backend "local" {
path = "relative/path/to/terraform.tfstate"
}
}
terraform.tfstate and its backup
By default, Terraform stores each workspace's state in a local file named terraform.tfstate, and a backup of the previous state in terraform.tfstate.backup[3]. A workspace here is just a named, independent state in the same directory; the default one lands in this top-level file, and the workspaces section below covers the rest. The file is JSON, it sits in the root module's working directory, and a successful apply rewrites it to record the change it just made. Storing state locally requires no additional configuration[3], which is exactly why it is the default you get for free.
Its two arguments: path and workspace_dir
The local backend exposes only two optional arguments. path is the path to the state file and defaults to terraform.tfstate relative to the root module[2]; set it to rename or relocate the file. workspace_dir is the path to non-default workspaces[2]; it defaults to the terraform.tfstate.d directory covered in the workspaces section below.
Locking is built in
State locking is not exclusive to remote backends. The local backend acquires its lock through operating-system file-locking APIs[2] rather than an external service, so two Terraform runs on the same machine cannot write the file at once. That lock lives on one machine, which is the key limitation: it guards a single operator, not teammates running Terraform from different hosts.
The figure shows the whole picture. A configuration with no backend block resolves to the local backend, which runs operations on your machine and keeps state, plus its backup, in files on local disk.
Legacy state flags: -state, -state-out, -backup
When you use the local backend, three command-line flags point the state read, the state write, and the backup at explicit filenames. Treat them as historical: this section of the docs describes legacy features preserved for backward compatibility that HashiCorp no longer recommends[2]. Know them anyway, because an exam item can hinge on what they do and on how they interact with workspaces.
The three flags map onto read, write, and backup
-state=FILENAMEoverrides the state filename when reading the prior state snapshot[2].-state-out=FILENAMEoverrides the state filename when writing new state snapshots[2]. If you set -state without -state-out, Terraform uses the -state filename for both, overwriting the input file when it writes a new snapshot[2].-backup=FILENAMEoverrides the backup filename the local backend would otherwise choose[2]. The default backup is the state file's name with a.backupsuffix (soterraform.tfstate.backupfor the default file), and-backup=-, a single ASCII dash, disables the creation of backup files altogether[2].
They bypass workspace file selection
Here is the trap. These flags name state files directly, so when you pass them the selected workspace no longer determines the state filename[4]. Passing -state does not switch workspaces and it does not read a workspace's terraform.tfstate.d file; it steps around workspace-based file selection entirely, which means you must manage a distinct filename per workspace yourself. Prefer setting path and using workspaces over reaching for these flags.
The figure traces one operation with the flags set: Terraform reads prior state from the -state file, writes the new snapshot to the -state-out file, and writes a copy to the -backup file unless -backup=- turns it off.
Workspaces and where their state files go
Terraform workspaces let one working directory hold several independent states, and with the local backend each workspace is just a different file on disk. Every initialized working directory starts with one workspace named default[5], and Terraform starts with a single, default workspace named default that you cannot delete[4].
The default workspace uses the plain path; others live under terraform.tfstate.d
The rule to remember: only non-default workspaces get a subdirectory. The default workspace stores its state directly at terraform.tfstate (or your configured path). Every other workspace's state goes under a directory Terraform names terraform.tfstate.d[5], one child per workspace, as terraform.tfstate.d/<workspace_name>/terraform.tfstate. The workspace_dir backend argument[2] overrides that parent directory name when you need the files elsewhere.
Managing workspaces
The terraform workspace command family manages these named states:
| Subcommand | What it does |
|---|---|
terraform workspace new NAME | Creates a new workspace[6] and switches to it |
terraform workspace select NAME | Switches to an existing workspace |
terraform workspace list | Lists all workspaces, marking the current one with an asterisk[7] |
terraform workspace show | Outputs the current workspace name[8] |
terraform workspace delete NAME | Deletes an empty workspace |
Deletion has guardrails: the target must not be your current workspace and must not still be tracking resources unless you pass -force[9], and the default workspace cannot be deleted at all. Inside configuration, read the active workspace with the terraform.workspace value[4].
The figure shows the on-disk layout for a directory with three workspaces: default at the top-level terraform.tfstate, and prod and staging each under their own terraform.tfstate.d subdirectory.
Exam-pattern recognition
TA-004 items on the local backend usually test a misconception, and no cloud-specific knowledge is required. Each pattern below pairs the tempting wrong answer with the plain behavior established above.
'No backend block' does not mean 'no backend'
When a stem shows a configuration with no backend and asks where state goes, the answer is the local backend and terraform.tfstate on disk, because local is the default backend[1]. An option claiming Terraform refuses to store state, or keeps it only in memory, is the trap.
Locking is not a remote-only feature
If an item implies you must adopt a remote backend just to get state locking, that is wrong. The local backend already locks state using system APIs[2]. The real limit is scope: that lock covers one machine, so the reason to move to a remote backend is shared state across a team, not the absence of any lock.
-state does not change workspaces
A stem that treats -state=FILENAME as a way to switch workspaces is testing the legacy-flag trap. Passing the legacy flags means the selected workspace no longer determines the state filename[4], so -state bypasses workspace selection rather than performing it; use terraform workspace select to switch, and -state only when you deliberately want to name a file.
Only non-default workspaces use terraform.tfstate.d
If asked where the default workspace's state lives, it is the top-level terraform.tfstate, not a subdirectory. Only non-default workspaces are filed under terraform.tfstate.d[5] as terraform.tfstate.d/<name>/terraform.tfstate; an answer that puts every workspace, including default, inside that directory is wrong.
You cannot delete the current or default workspace
When a scenario tries to delete the workspace you are on, or the default workspace, the operation fails. terraform workspace delete requires that the target is not your current workspace and is not still tracking resources unless -force is set[9], and the default workspace cannot be deleted[4] at all.
Where state lives and where runs happen, by backend
| Aspect | Local backend | Remote backend (e.g. s3) | HCP Terraform (cloud block) |
|---|---|---|---|
| Where state is stored | terraform.tfstate on your local disk | A remote object store or database you configure | Stored and managed by HCP Terraform |
| Where operations run | Your local machine | Your local machine | Remote or agent execution by default |
| State locking | System file-locking APIs, one machine | Backend-specific locking service | Automatic and managed |
| Built for team collaboration | No, single operator | Yes, shared remote state | Yes, with run history and access controls |
| Configuration block | backend "local", or none | backend "<type>" | cloud |
Decision tree
Sharp facts the exam loves — give these one last read before exam day.
Cheat sheet
Sharp facts the exam loves — scan these before test day.
- Local backend is the default and writes terraform.tfstate
If a configuration has no backend or cloud block, Terraform uses the local backend, which stores state as a file named terraform.tfstate in the root module's working directory and performs all operations on the local machine.
Trap The local backend is not 'no backend' — it is a real backend Terraform selects by default.
8 questions test this
- An engineer initializes a project that relies on the default local backend and runs a first `terraform apply`. What is the exact name of the file Terraform creates to hold the current state in the wor
- A teammate joins a project whose configuration contains no `backend` block and no `cloud` block. Seeing `terraform apply` succeed, they assume Terraform must be saving the state to HashiCorp's servers
- During a code review, a colleague looks at a Terraform configuration that contains no `backend` block and no `cloud` block and concludes, 'Since we never configured a backend, this project isn't using
- An engineer runs `terraform plan` and `terraform apply` for a configuration that uses the default local backend directly from their laptop. With respect to where the work happens and where the state l
- A platform engineer writes a new Terraform configuration that contains provider and resource blocks but no `backend` block and no `cloud` block, then runs `terraform apply` from their workstation. How
- A developer new to Terraform writes a configuration with only `provider` and `resource` blocks - no `backend` block and no `cloud` block - and worries that their infrastructure state will be lost betw
- To keep environment state files together, an engineer configures the local backend with `path = "state/prod.tfstate"` inside a `backend "local"` block and runs Terraform from the default workspace. Wh
- A configuration uses the default local backend and does not set the `path` argument. Relative to the project files, in which location does Terraform create the `terraform.tfstate` file?
- The path argument overrides the local state file location
The local backend's optional path argument sets the filename and location of the state file; when omitted it defaults to terraform.tfstate relative to the root module.
7 questions test this
- To keep environment state organized, an engineer configures the local backend with `path = "envs/prod/terraform.tfstate"` in their `backend "local"` block and applies from the default workspace. What
- An existing project has been applying with the default local backend and already has a populated `terraform.tfstate`. An engineer edits the `backend "local"` block to add `path = "infra/main.tfstate"`
- A configuration contains a `terraform { backend "local" {} }` block with no arguments inside it - in particular, the `path` argument is omitted. When the engineer runs Terraform, which state file does
- A team standardizing their repository layout wants Terraform to write the default workspace's state to `secrets/team.tfstate` instead of the usual `terraform.tfstate`, while still using the local back
- A developer new to Terraform writes a configuration with only `provider` and `resource` blocks - no `backend` block and no `cloud` block - and worries that their infrastructure state will be lost betw
- To keep environment state files together, an engineer configures the local backend with `path = "state/prod.tfstate"` inside a `backend "local"` block and runs Terraform from the default workspace. Wh
- A configuration uses the default local backend and does not set the `path` argument. Relative to the project files, in which location does Terraform create the `terraform.tfstate` file?
- Local backend locks state using system APIs
The local backend supports state locking, acquiring the lock through operating-system file-locking APIs rather than an external service.
Trap State locking is not exclusive to remote backends; the default local backend also locks state.
- -state and -state-out override read/write state files
For the local backend, -state=FILENAME overrides the file Terraform reads prior state from and -state-out=FILENAME overrides the file it writes the new state snapshot to; when -state-out is unset it defaults to the -state path.
10 questions test this
- In a directory with a `prod` workspace selected, an engineer runs `terraform apply -state-out=prod-out.tfstate`. Normally the prod workspace's state lives under terraform.tfstate.d/prod. When -state-o
- An engineer's configuration declares an `s3` backend for remote state and wants to redirect where the new state snapshot is written by adding `-state-out=custom.tfstate` to `terraform apply`. What is
- A practitioner has selected the `dev` workspace in a working directory that uses the local backend, then runs `terraform apply -state=shared.tfstate`. How does supplying -state affect which state file
- Working in the default workspace with the local backend, an engineer wants a `terraform apply` to leave the existing `terraform.tfstate` untouched and write the resulting snapshot to `candidate.tfstat
- A practitioner selects the `staging` workspace in a local-backend directory and runs `terraform apply -state=staging-manual.tfstate` to push an out-of-band fix. The next day, still on the `staging` wo
- An engineer wants a `terraform plan` on a local-backend configuration to read prior state from a custom file and also write the refreshed snapshot to a different custom file during planning. Which leg
- The Terraform documentation labels -state, -state-out, and -backup as legacy options it no longer recommends. According to that documentation, what original workflow were these three options preserved
- An engineer using the local backend runs `terraform apply -state=service.tfstate` and passes no -state-out option. The apply provisions new resources and completes successfully. Because -state-out was
- An engineer keeps two independent local state files, `frontend.tfstate` and `backend.tfstate`, in one working directory instead of using workspaces. To have `terraform plan` build its plan by comparin
- While scripting a disposable local-backend run, an engineer wants Terraform to skip creating the automatic .backup file that the local backend writes alongside the new state snapshot. Which value pass
- -backup writes a state backup and -backup=- disables it
The local backend writes a backup of the previous state to .backup by default; the -backup=FILENAME flag overrides that path, and -backup=- disables backups entirely.
- Legacy -state flags override workspace file selection
When you pass -state or -state-out, the selected workspace no longer determines the state filename, so you must manage distinct filenames per workspace yourself.
Trap Using -state does not switch workspaces; it bypasses workspace-based file selection entirely.
6 questions test this
- In a directory with a `prod` workspace selected, an engineer runs `terraform apply -state-out=prod-out.tfstate`. Normally the prod workspace's state lives under terraform.tfstate.d/prod. When -state-o
- A practitioner has selected the `dev` workspace in a working directory that uses the local backend, then runs `terraform apply -state=shared.tfstate`. How does supplying -state affect which state file
- A teammate believes that running `terraform apply -state=staging.tfstate` is a shortcut for switching to a workspace named 'staging' before applying. Evaluate this belief about what the -state option
- A practitioner selects the `staging` workspace in a local-backend directory and runs `terraform apply -state=staging-manual.tfstate` to push an out-of-band fix. The next day, still on the `staging` wo
- A team has three workspaces (default, staging, prod) in one local-backend directory and standardizes on always passing `-state=terraform.tfstate` to every apply for consistency. What risk does this pr
- An engineer keeps two independent local state files, `frontend.tfstate` and `backend.tfstate`, in one working directory instead of using workspaces. To have `terraform plan` build its plan by comparin
- Non-default workspaces live under terraform.tfstate.d
With the local backend, each non-default workspace's state is stored at terraform.tfstate.d//terraform.tfstate instead of the top-level state file.
12 questions test this
- A teammate new to Terraform asks how the local backend decides where to keep state for the built-in default workspace versus a workspace they created called reporting. Which statement correctly descri
- In a local-backend project, an engineer creates two workspaces, blue and green, and runs `terraform apply` in each. Inspecting the working directory afterward, which description best matches what Terr
- After spending the afternoon in a workspace named prod on a local-backend project, an engineer switches back by running `terraform workspace select default` and then runs `terraform apply`. Where does
- An engineer working with the local backend runs `terraform workspace new payments` and then runs `terraform apply` while the payments workspace is selected. On disk, which file now holds the state for
- A project on the local backend has both the default workspace and a prod workspace, so a terraform.tfstate.d/prod/terraform.tfstate file exists on disk. A teammate asks where the default workspace's o
- An engineer inspects a Terraform project that has only ever used the default workspace with the local backend and looks for a terraform.tfstate.d directory to back up. They find that no such directory
- An engineer has been managing infrastructure on the default workspace only, so its state sits in terraform.tfstate. They now run `terraform workspace new dev` to start a second environment. What happe
- A team keeps one Terraform configuration on the local backend and drives three environments from it using the workspaces dev, qa, and prod, alongside the untouched default workspace. How does Terrafor
- An engineer is moving a local-backend Terraform project to a new workstation and must manually copy every state file so that both the default workspace and a non-default prod workspace keep their stat
- An engineer opens a colleague's local-backend Terraform project for the first time and notices a terraform.tfstate.d directory that contains a single subfolder named prod. Before running anything, wha
- After creating a workspace named dev and running terraform apply in a project backed by the local backend, an engineer notices a new terraform.tfstate.d directory in the working directory that was not
- An engineer manages one Terraform configuration on the local backend and creates a workspace named staging in addition to the existing default workspace. After selecting staging and running terraform
- The default workspace uses the plain terraform.tfstate path
The default workspace stores its state directly at terraform.tfstate (or the configured path), not inside the terraform.tfstate.d directory.
Trap Only non-default workspaces use terraform.tfstate.d; the default workspace is not placed in a subdirectory.
9 questions test this
- A teammate new to Terraform asks how the local backend decides where to keep state for the built-in default workspace versus a workspace they created called reporting. Which statement correctly descri
- In a local-backend project, an engineer creates two workspaces, blue and green, and runs `terraform apply` in each. Inspecting the working directory afterward, which description best matches what Terr
- After spending the afternoon in a workspace named prod on a local-backend project, an engineer switches back by running `terraform workspace select default` and then runs `terraform apply`. Where does
- A project on the local backend has both the default workspace and a prod workspace, so a terraform.tfstate.d/prod/terraform.tfstate file exists on disk. A teammate asks where the default workspace's o
- An engineer inspects a Terraform project that has only ever used the default workspace with the local backend and looks for a terraform.tfstate.d directory to back up. They find that no such directory
- An engineer has been managing infrastructure on the default workspace only, so its state sits in terraform.tfstate. They now run `terraform workspace new dev` to start a second environment. What happe
- An engineer is moving a local-backend Terraform project to a new workstation and must manually copy every state file so that both the default workspace and a non-default prod workspace keep their stat
- An engineer opens a colleague's local-backend Terraform project for the first time and notices a terraform.tfstate.d directory that contains a single subfolder named prod. Before running anything, wha
- An engineer manages one Terraform configuration on the local backend and creates a workspace named staging in addition to the existing default workspace. After selecting staging and running terraform
- workspace_dir sets the non-default workspace directory
The local backend's optional workspace_dir argument overrides the default terraform.tfstate.d directory used to hold non-default workspace state files.
- terraform workspace subcommands
The terraform workspace command family manages named workspaces that each keep their own separate state: new creates and switches to a workspace, select switches to an existing one, list shows all workspaces (marking the current one with an asterisk), show prints the current workspace name, and delete removes an empty workspace. Terraform always starts with a workspace named default, which cannot be deleted.
Trap You cannot delete the workspace you are currently on or the default workspace, and delete refuses to remove a workspace whose state still tracks resources unless forced.
5 questions test this
- An engineer has several workspaces in a local-backend project and, before running a plan, wants Terraform to print only the name of the workspace that is currently selected. Which command does exactly
- Earlier in the sprint an engineer created a workspace named sandbox in a local-backend project. Today, while on the default workspace, they need to switch back to the already-existing sandbox workspac
- While cleaning up an old project, an engineer decides the built-in default workspace is unnecessary and runs terraform workspace delete default from a different, currently selected workspace. Accordin
- An engineer has been managing infrastructure on the default workspace only, so its state sits in terraform.tfstate. They now run `terraform workspace new dev` to start a second environment. What happe
- An engineer no longer needs a workspace called old-test whose local state still tracks several running resources. While selected on the default workspace, they run terraform workspace delete old-test.