Module 6: Terraform State Management

Lesson 6.1: The Local Backend

Plain language

A backend determines where Terraform stores state. With no backend block (and no cloud block), Terraform uses the local backend:

File Purpose
terraform.tfstate Current state, in the working directory
terraform.tfstate.backup The previous state, written just before each state change
terraform.tfstate.d/<workspace>/terraform.tfstate State for non-default CLI workspaces (Lesson 6.5)

You can configure the local backend explicitly, for example to change the path:

HCL
terraform {
  backend "local" {
    path = "state/terraform.tfstate"
  }
}

Under the hood

  • The local backend does lock state, using operating-system file locks. That only protects processes on the same machine.
  • The legacy -state=PATH CLI flag works only with the local backend.

Why local state doesn't work for teams

Problem Effect
No sharing Each person's laptop has a different "truth"
No cross-machine locking Concurrent applies from two laptops can corrupt infrastructure
Secrets on disk State is plaintext (Module 2), and laptops get lost or backed up to unmanaged places
No history or audit Only one .backup file is kept
Easy to lose Delete the directory and Terraform forgets everything it manages