State file overview

Terraform state is a persistent data store that tracks the current state of infrastructure resources provisioned by Terraform, allowing it to manage changes and track resource dependencies.

Every time Terraform runs, it records information about what infrastructure has been worked with in a state file. By default, assuming you haven’t configured remote backend state this file is saved to the Terraform working directory as two files called terraform.state and terraform.state.backup. The state file is a JSON file and can be read by you if required in any text editor.

When you run terraform plan, Terraform reads the current state of the infrastructure resources from the state file and compares it to the desired state specified in the configuration files. It then calculates the difference, or plan, between the two states and shows you what actions Terraform would take to bring the actual resources into alignment with the desired state. This allows you to preview the changes that would be made before applying them, helping to prevent unintended or destructive changes to your infrastructure.

Last modified July 21, 2024: update (e2ae86c)