Courseiva
Implement and maintain statehardMultiple ChoiceObjective-mapped

TF-004 State manipulation Practice Question

After running `terraform state mv` to rename a resource, the resource's state binding is lost and the resource cannot be managed. Which command should be run to restore the state binding?

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 import

After a failed `terraform state mv`, the resource mapping in the state may become corrupted or lost. To restore the binding, use `terraform import` to re-import the existing resource into the state. Option E, `terraform import`, is correct. Option D, `terraform refresh`, updates the state to match real infrastructure but does not restore a missing resource binding.

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 it's wrong here

    terraform state push is a command used to manually upload a local Terraform state file to a configured remote backend. This operation is primarily for state file management and synchronization, ensuring the remote backend has the most current state. It has no functionality to re-establish a binding between a resource definition in configuration and an existing, potentially misaligned, resource entry in the state file after a terraform state mv operation.

  • terraform state show

    Why it's wrong here

    terraform state show is an inspection command that outputs the current state of resources as recorded in the Terraform state file. It allows users to view the attributes and details of managed resources, providing visibility into Terraform's understanding of the infrastructure. This command is read-only and performs no operations that could re-establish a broken binding or modify the state file's relationship with remote resources.

  • terraform state rm

    Why it's wrong here

    terraform state rm is used to remove one or more resource instances from the Terraform state file. This action effectively tells Terraform to stop managing the specified resource, making it an unmanaged object. After renaming a resource with terraform state mv, using terraform state rm would further break the connection by deleting the state entry, rather than re-establishing the binding to the underlying infrastructure.

  • terraform refresh

    Why it's wrong here

    terraform refresh is designed to reconcile the Terraform state file with the actual attributes of existing remote objects without making any changes to the infrastructure. While it updates the state, it does not re-establish a broken binding where Terraform's internal identifier for a resource no longer correctly points to the live infrastructure. It cannot "find" a resource that terraform state mv might have inadvertently disconnected from its actual remote ID.

  • terraform import

    Why this is correct

    After terraform state mv renames a resource in the state, the provider might lose its ability to correctly identify the corresponding remote object if the underlying resource ID or its lookup mechanism changes. terraform import allows you to explicitly tell Terraform to bring an existing remote resource, identified by its actual cloud provider ID, under management for a specific resource block in your configuration. This effectively re-establishes the binding by creating a new, correct state entry that links the configuration to the live infrastructure.

About these practice questions

One of 428 original TF-004 practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

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.