Skip to content

004 · Domain 6: Terraform state management · 13% of the exam

Task 6.1: Describe the local backend

The default backend: state in terraform.tfstate on local disk, the backup file, workspaces under terraform.tfstate.d, the path argument, and why it does not suit a team.

Study it

  • The local backend: files, backups and workspaces

    Lesson coming

Sample questions

Try each one before opening the answer. Every option is explained, with the HashiCorp documentation page that proves it.

Question 1 · choose 1

A developer uses the default local backend and creates CLI workspaces named dev and test in addition to default. Where does Terraform keep the dev workspace's state?

  1. AIn terraform.tfstate, as a separate section labeled dev
  2. BIn terraform.tfstate.d/dev/terraform.tfstate
  3. CIn .terraform/workspaces/dev.tfstate, managed by terraform init
  4. DIn the dependency lock file, under a workspace "dev" entry
Show the answer and why
  • AIn terraform.tfstate, as a separate section labeled dev

    Incorrect

    Each non-default workspace has its own state file in its own directory.

  • BIn terraform.tfstate.d/dev/terraform.tfstate

    Correct

    The local backend keeps the default workspace in terraform.tfstate and other workspaces under the terraform.tfstate.d directory.

  • CIn .terraform/workspaces/dev.tfstate, managed by terraform init

    Incorrect

    .terraform holds providers, modules and backend settings, not workspace states.

  • DIn the dependency lock file, under a workspace "dev" entry

    Incorrect

    The lock file has no workspace entries and never holds state.

With the local backend, default lives in terraform.tfstate and every other workspace in terraform.tfstate.d/<name>/.

Question 2 · choose 1

A configuration has neither a backend block nor a cloud block. Which backend does Terraform use?

  1. AThe local backend
  2. BThe remote backend for app.terraform.io
  3. CAn in-memory backend that discards state after each run
  4. DWhichever backend was used by the last configuration on the machine
Show the answer and why
  • AThe local backend

    Correct

    Terraform uses a backend called local by default, which stores state as a local file on disk.

  • BThe remote backend for app.terraform.io

    Incorrect

    HCP Terraform is used only when configured.

  • CAn in-memory backend that discards state after each run

    Incorrect

    The default backend persists state to disk.

  • DWhichever backend was used by the last configuration on the machine

    Incorrect

    Each configuration has its own backend setting.

No backend block means local state.

Question 3 · choose 1

Besides storing state on disk, what does the local backend do?

  1. AIt keeps every configuration's state in one file in the home directory
  2. BIt encrypts the state file with the operating system's key store
  3. CIt runs operations such as plan and apply locally
  4. DIt keeps a second copy of the state in the .terraform directory
Show the answer and why
  • AIt keeps every configuration's state in one file in the home directory

    Incorrect

    Local state belongs to each working directory: a terraform.tfstate file next to the configuration it describes.

  • BIt encrypts the state file with the operating system's key store

    Incorrect

    The local backend has no encryption setting.

  • CIt runs operations such as plan and apply locally

    Correct

    The local backend stores state on the local filesystem and performs operations locally.

  • DIt keeps a second copy of the state in the .terraform directory

    Incorrect

    The .terraform directory holds the working directory's backend settings, not a copy of the state.

With the local backend, the state sits on the machine's disk and plan and apply run on that same machine.

Question 4 · choose 1

A configuration uses a remote backend, yet a file named terraform.tfstate appears inside the .terraform directory. What is it?

  1. AA full copy of the remote state, cached there so that plans can run offline
  2. BThe state of the default workspace before migration
  3. CA lock marker that shows a run is in progress
  4. DThe backend configuration for this working directory
Show the answer and why
  • AA full copy of the remote state, cached there so that plans can run offline

    Incorrect

    Remote state is held in memory during runs, not cached in .terraform.

  • BThe state of the default workspace before migration

    Incorrect

    Local state for the default workspace is terraform.tfstate in the working directory.

  • CA lock marker that shows a run is in progress

    Incorrect

    Locks are handled by the backend.

  • DThe backend configuration for this working directory

    Correct

    .terraform/terraform.tfstate contains the backend configuration for the current working directory; the infrastructure state lives in the backend.

Same file name, different purpose: .terraform/terraform.tfstate is backend settings, not your infrastructure.

Question 5 · choose 1

When is the default local backend a reasonable choice, according to the state documentation?

  1. AFor production teams, because local files are the fastest backend available
  2. BNever; Terraform warns on every run with local state
  3. COnly inside HCP Terraform workspaces
  4. DFor getting started; teams need one shared state
Show the answer and why
  • AFor production teams, because local files are the fastest backend available

    Incorrect

    Speed is not the issue; sharing and locking across people are.

  • BNever; Terraform warns on every run with local state

    Incorrect

    Local state is valid and produces no warning.

  • COnly inside HCP Terraform workspaces

    Incorrect

    HCP Terraform workspaces store state remotely.

  • DFor getting started; teams need one shared state

    Correct

    Storing state in the working directory is fine to start with, but teams must all work with the same state, which remote backends provide.

Local state is a starting point; teams outgrow it.

Question 6 · choose 1

Before changing a configuration from local state to a remote backend, what does the backend documentation strongly recommend?

  1. ARun terraform destroy so nothing has to be migrated
  2. BBack up the state by copying terraform.tfstate somewhere safe
  3. CDelete the .terraform.lock.hcl file
  4. DRename every resource so the new backend creates fresh addresses
Show the answer and why
  • ARun terraform destroy so nothing has to be migrated

    Incorrect

    Destroying infrastructure is never a migration step.

  • BBack up the state by copying terraform.tfstate somewhere safe

    Correct

    The docs strongly recommend manually backing up the state file before migrating to a new backend.

  • CDelete the .terraform.lock.hcl file

    Incorrect

    The lock file is unrelated to state migration.

  • DRename every resource so the new backend creates fresh addresses

    Incorrect

    Renames would make Terraform plan replacements.

A copy of the local state file is the cheapest insurance for a migration.

Practise domain 6 →Practise all domains →