terraform state push command uploads a local state file to the configured backend, overwriting the remote state.
Synopsis
Update remote state from a local state file.Usage
-force flag.
This command works with local state (it will overwrite the local state), but is less useful for this use case.
If PATH is ”-”, then this command will read the state to push from stdin. Data from stdin is not streamed to the backend: it is loaded completely (until pipe close), verified, and then pushed.
Options
Write the state even if lineages don’t match or the remote serial is higher.
Don’t hold a state lock during the operation. This is dangerous if others might concurrently run commands against the same workspace.
Duration to retry a state lock.
Arguments
Path to the local state file to push. Use ”-” to read from stdin.
Examples
Push a local state file
Push a local state file to the remote backend:Push from stdin
Push state from stdin:Force push
Force push even if the lineage or serial number doesn’t match:-force with extreme caution as it can overwrite newer state with older state.
Restore from backup
Restore state from a backup file:Push without locking
Push state without acquiring a lock (not recommended):Push with lock timeout
Specify a timeout for acquiring the state lock:Common Use Cases
Restore from backup
Restore state after accidental changes or corruption:Migrate state to new backend
Move state from one backend to another:Recover from state loss
Recover state if the remote backend loses the state file:Fix state corruption
Manually edit and repair a corrupted state file, then push it back:Sync state after manual editing
After making manual state modifications locally:Important Notes
- Dangerous operation: This overwrites remote state and can cause data loss
- State lineage and serial number are checked to prevent accidental overwrites
- Use
-forceonly when you’re certain you want to overwrite the remote state - Always create a backup before pushing state:
- The state file must be in valid JSON format
- Pushing state doesn’t run any validation of the infrastructure
- Other team members should not be running Terraform operations during a push
Safety Checks
Terraform performs several safety checks before pushing state:- Lineage check: Verifies the state file lineage matches the remote state
- Serial number check: Ensures the serial number is not lower than the remote state
- State lock: Acquires a lock to prevent concurrent modifications
-force, but doing so risks:
- Overwriting newer state with older state
- Losing recent infrastructure changes
- Creating state inconsistencies
When to Use Force
Use-force only in specific scenarios:
- Recovering from a failed migration
- Restoring from a backup when the remote state is corrupted
- Fixing state after a backend failure
- You’re certain the local state is the correct version
-force in shared environments.