Terraform state
Terraform's record, usually a JSON file called terraform.tfstate, mapping each resource in the configuration to the real object it created.
State files can hold secrets and losing or corrupting one breaks management of real resources.
In more detail
State is how Terraform knows which real objects it owns, so plans can compare configuration, state and reality. It records every attribute, including passwords and keys, in plain text, even for values marked sensitive. Never edit it by hand, keep it out of Git, back it up, and share it through a remote backend with locking.
Related terms
- Terraform — An infrastructure-as-code tool from HashiCorp that creates and changes cloud resources such as servers, networks and databases from configuration files.
- terraform plan — The command that compares configuration, state and reality and prints the actions needed to make them match, without changing anything.
- Terraform backend — The setting that decides where Terraform stores state and how it locks it, from a local file to shared cloud storage.
- sensitive value — A variable or output marked sensitive = true, which Terraform hides in plan output and the terminal but still stores in state in plain text.
- state locking — Preventing two Terraform runs from writing the same state at once, by taking a lock before any operation that could change it.
- refresh — Terraform asking each provider what the resources recorded in state really look like now, before it plans.
- state backup — A saved copy of the state from before a change, kept so you can recover if the state is damaged or a repair goes wrong.
Related guides
Taught in
- Infrastructure as Code (Handover to Terraform) — Cloud Infrastructure & Hyperscaler Architecture
- Two Environments That Should Have Been Twins — CompTIA Cloud+ (CV0-004) Exam Prep
- Deployment Sprint: A Plan That Deletes The App Server — CompTIA Cloud+ (CV0-004) Exam Prep
- Continuous IaC Drift Detection & State Protection — Cloud Security & DevSecOps Engineering
- Predicting Changes, Then Applying Them — Infrastructure as Code with Terraform
- Tearing It Down With Destroy — Infrastructure as Code with Terraform
- Parameterising With Input Variables — Infrastructure as Code with Terraform
- Return Values: Outputs And Locals — Infrastructure as Code with Terraform
- What State Really Is And Why It Is Needed — Infrastructure as Code with Terraform
- Simulating A Managed Database — Infrastructure as Code with Terraform
- Detecting And Fixing Configuration Drift — Infrastructure as Code with Terraform
- Importing Existing Resources — Infrastructure as Code with Terraform
- Forcing Replacement — Infrastructure as Code with Terraform
- The Problem With Local State — Infrastructure as Code with Terraform
- Configuring A Remote Backend — Infrastructure as Code with Terraform
- State Locking With Use Lockfile — Infrastructure as Code with Terraform
- Workspaces For Multiple Environments — Infrastructure as Code with Terraform
- Security: Secrets In State And Ephemeral Values — Infrastructure as Code with Terraform
- The Plan That Wanted To Destroy Production — HashiCorp Terraform Associate (004) Exam Prep
- One Hour, No Weights Published — HashiCorp Terraform Associate (004) Exam Prep
- Infrastructure As Code, And One Workflow For Every Platform — HashiCorp Terraform Associate (004) Exam Prep
- Providers: How Terraform Reaches Every API — HashiCorp Terraform Associate (004) Exam Prep
- Versions, The Lock File And Provider Aliases — HashiCorp Terraform Associate (004) Exam Prep
- State: Terraform's Memory Of What It Built — HashiCorp Terraform Associate (004) Exam Prep
- Write, Plan, Apply, And What Init Prepares — HashiCorp Terraform Associate (004) Exam Prep
- Reading A Plan, Saving It, Applying It — HashiCorp Terraform Associate (004) Exam Prep