Terraform

Why does Terraform keep state and how do local and remote state differ?

Difficulty: unrated

Source: bregman-arie/devops-exercises by Arie Bregman

Answer

Terraform stores state to map real infrastructure objects to the resources declared in code, keep track of dependencies, detect drift, and speed up planning by caching attribute data.

  • Local state is stored in a terraform.tfstate file on disk and is suitable for quick experiments or single-operator workflows.

  • Remote state lives in a backend (such as S3, GCS, Terraform Cloud) that can enforce locking, access controls, and versioning so teams share a single source of truth.

    Always choose a remote backend once there is more than one operator or automation pipeline touching the configuration.