# Terraform State

> The Terraform state is the file where Terraform and OpenTofu record which real resources they manage, so they can plan and apply changes.

- Source: https://www.itwonderlab.com/terraform-state/
- Published: 2026-06-24
- Updated: 2026-06-24
- Author: Javier Ruiz Jiménez (https://www.javierruizjimenez.com/)
- Site: IT Wonder Lab (https://www.itwonderlab.com/)

---

**Terraform state** is a JSON file (`terraform.tfstate`) where Terraform and OpenTofu store the mapping between the resources in your code and the real objects in the cloud, plus their attributes. On every `plan`, the tool refreshes the state, compares it with the code and calculates the changes.

### Why it matters

- Without the state, Terraform could not know that `aws_instance.web` is the instance `i-0abc123`.
- It contains **sensitive data** in plain text (passwords, keys), so it must be protected: see [secrets management](https://www.itwonderlab.com/terraform-secrets-management/) and [state encryption](https://www.itwonderlab.com/terraform-state-file-encryption/).
- It must be shared and **locked** in a team, which is the job of a [backend](https://www.itwonderlab.com/terraform-backend/).
- Never edit it by hand. Use `terraform state` commands or [import, moved and removed](https://www.itwonderlab.com/terraform-import-moved-removed/) blocks.

### Related

[Backends tutorial](https://www.itwonderlab.com/aws-terraform-tutorial-terraform-backends/), [workspaces](https://www.itwonderlab.com/terraform-workspace/), [drift](https://www.itwonderlab.com/terraform-drift/) and the [cheat sheet](https://www.itwonderlab.com/terraform-cheat-sheet/).
