TF-004 Understand Terraform basics Practice Question
A developer runs terraform plan and sees a large number of resources will be destroyed. They suspect the state file is corrupted. They have a recent backup of the state file. Which command can help recover the previous state from the backup?
⚠ Common exam trap
Many exam-takers confuse `terraform state push` with `terraform state pull`, assuming that pulling a backup file is the recovery action, but only `push` can overwrite the remote state with a local backup.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
terraform state push
The `terraform state push` command is used to manually upload a local state file to the remote backend, overwriting the current remote state. In this scenario, the developer can use a recent backup of the state file and run `terraform state push` to restore the previous state, effectively recovering from the corruption. This command directly replaces the remote state with the specified local file, allowing Terraform to revert to the known good state.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✓
terraform state push
Why this is correct
When a Terraform state file becomes corrupted or is accidentally deleted, and a valid backup of the state file exists locally, `terraform state push` is the command used to upload this backup to the configured remote backend. This action overwrites the current (potentially invalid or missing) state in the backend with the provided backup, effectively restoring the infrastructure's known state. This allows subsequent `terraform plan` and `apply` operations to correctly reflect the deployed resources.
- ✗
No command can recover; they must re-import all resources.
Why it's wrong here
This statement is incorrect because Terraform provides mechanisms to recover from state issues, particularly when a backup of the state file is available. While re-importing resources using `terraform import` is a valid strategy for bringing existing infrastructure under Terraform management, it is a time-consuming and often complex process. It is not the primary or necessary recovery method if a functional state file backup exists, as `terraform state push` offers a direct restoration path.
- ✗
terraform state rm
Why it's wrong here
The `terraform state rm` command is used to remove one or more resources from the Terraform state file, effectively telling Terraform to "forget" about those specific resources. This operation does not delete the actual cloud resources, but it removes their mapping from the state, making them unmanaged by Terraform. Therefore, using `terraform state rm` would exacerbate a state corruption problem by further reducing the known state, rather than restoring it.
- ✗
terraform state pull
Why it's wrong here
The `terraform state pull` command is designed to download the *current* state file from the configured remote backend to a local file. Its primary purpose is to inspect the active state or to create a local copy for debugging or archival. If the remote state is already corrupted or missing, pulling it down would only retrieve the problematic state or an empty file, offering no mechanism to restore from a separate, valid backup.
Go deeper
Related to this question
About these practice questions
This TF-004 question is part of Courseiva's 428-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. Learn why practice questions differ from exam dumps →
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This TF-004 practice question is part of Courseiva's free HashiCorp certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the TF-004 exam.