state file
What is state file?
state file: Terraform’s record of the real resources it manages and how they map to your config. Source of truth for what exists. The state file is Terraform's record of the infrastructure it manages. It maps each resource in your configuration to a real object, such as a server ID or bucket name, and stores its current attributes.
Frequently asked questions about state file
How is state file used in practice?
Terraform compares your configuration, the state and the real infrastructure to work out what to change. Without the state, it would not know which existing resources belong to it.
What should you keep in mind with state file?
Treat the state file as sensitive and important. It often contains secrets in plain text, such as database passwords, so keep it in a secured remote backend, not in Git. Enable versioning, so you can recover from mistakes, and use locking so two people cannot write it at once. terraform state list shows what is tracked, and editing the file by hand is almost never the right fix.
What does an example of state file look like?
terraform state list At a glance
| Category | Terraform |
|---|---|
| Explained by | Reinier de la Parra |
| Updated |