0
0
Terraformcloud~10 mins

Terraform state pull and push - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - Terraform state pull and push
Start
Run 'terraform state pull'
Download current state file
Modify state file locally (optional)
Run 'terraform state push'
Upload updated state file
End
This flow shows how Terraform downloads the current state, optionally modifies it locally, then uploads the updated state back.
Execution Sample
Terraform
terraform state pull > terraform.tfstate
# (edit state file locally)
terraform state push terraform.tfstate
Pulls the current Terraform state, allows local changes, then pushes the updated state back.
Process Table
StepCommandActionResult
1terraform state pull > terraform.tfstateDownload state file from backendState file saved locally
2Local edit (optional)Modify state file contentState file updated locally
3terraform state push terraform.tfstateUpload local state file to backendBackend state updated
4-Verify state consistencyState matches local file
💡 State push completes, backend state matches local state file
Status Tracker
VariableStartAfter PullAfter Local EditAfter Push
state_fileemptydownloaded contentmodified contentuploaded content
Key Moments - 2 Insights
Why do we need to pull the state before pushing?
Pulling ensures you have the latest state file locally to avoid overwriting changes. See execution_table step 1 and 3.
What happens if the local state file is corrupted before pushing?
Pushing a corrupted state can break your Terraform setup. Always verify local edits before push (execution_table step 2).
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the result of 'terraform state pull' at step 1?
AState file saved locally
BState file uploaded to backend
CState file deleted
DNo change
💡 Hint
Check the 'Result' column in execution_table row 1
At which step does the backend state get updated?
AStep 1
BStep 2
CStep 3
DStep 4
💡 Hint
Look at the 'Action' and 'Result' columns in execution_table row 3
If you skip the pull and push a local state, what risk increases?
ANo risk, it's safe
BOverwriting newer backend state
CDeleting local files
DTerraform version mismatch
💡 Hint
Refer to key_moments about why pulling first is important
Concept Snapshot
terraform state pull: downloads current state file from backend
terraform state push: uploads local state file to backend
Always pull before push to avoid overwriting changes
Local edits to state file should be done carefully
Push updates backend state to match local file
Full Transcript
Terraform state pull downloads the current state file from the backend to your local machine. You can optionally edit this state file locally to fix or adjust resources. After editing, terraform state push uploads the updated state file back to the backend, replacing the previous state. This process ensures your local and backend states stay synchronized. Always pull before pushing to avoid overwriting newer changes in the backend. Be careful when editing the state file locally to prevent corruption.