What Is the OpenTofu State?
When you executetofu apply for the first time, OpenTofu generates a JSON state file named terraform.tfstate in your working directory, along with a backup terraform.tfstate.backup. This file records every resource managed by OpenTofu—its IDs, attributes, dependencies, and provider metadata.
Example configuration:
tofu plan and tofu apply.
State Refresh on plan and apply
Before creating an execution plan, OpenTofu refreshes the state by comparing it to real-world infrastructure:
Disabling State Refresh
You can bypass the refresh step with-refresh=false, though it’s generally not recommended:
Skipping state refresh may speed up large operations but risks applying changes on outdated state. Only use this flag if you fully understand the consequences.
Example: Updating a Resource In-Place
Suppose you update the instance type fromm5.large to t3.micro:
State Dependencies
OpenTofu tracks inter-resource dependencies to determine correct creation and destruction order. For example:terraform.tfstate, the web instance includes a dependencies array:
Best Practices for State Management
Configure remote backends to enable state locking and consistency. This prevents multiple users from making concurrent changes.