0
0
Terraformcloud~15 mins

Terraform state pull and push - Mini Project: Build & Apply

Choose your learning style9 modes available
Terraform State Pull and Push
📖 Scenario: You are managing infrastructure using Terraform. You need to safely retrieve the current state of your infrastructure and then update it after making changes.
🎯 Goal: Learn how to pull the current Terraform state into a local file and then push an updated state back to the remote backend.
📋 What You'll Learn
Use terraform state pull to download the current state
Save the pulled state into a file named terraform.tfstate
Modify the state file by adding a comment line
Use terraform state push to upload the updated state file
💡 Why This Matters
🌍 Real World
Managing Terraform state files is essential for tracking infrastructure changes and collaborating safely in teams.
💼 Career
Understanding state pull and push commands helps cloud engineers maintain infrastructure consistency and recover from state issues.
Progress0 / 4 steps
1
Pull the current Terraform state
Run the command terraform state pull and save its output into a file named terraform.tfstate.
Terraform
Need a hint?

Use the shell redirection operator > to save the output to a file.

2
Add a comment to the state file
Open the file terraform.tfstate and add a comment line // Updated state at the top of the file.
Terraform
Need a hint?

Use sed to insert a line at the beginning of the file.

3
Push the updated state back to Terraform
Use the command terraform state push terraform.tfstate to upload the updated state file back to the remote backend.
Terraform
Need a hint?

Use terraform state push followed by the filename to upload the state.

4
Verify the state push completion
Confirm that the command terraform state push terraform.tfstate was run to complete the state update process.
Terraform
Need a hint?

Ensure the push command is included to finalize the update.