Courseiva
Implement and maintain stateeasyMultiple ChoiceObjective-mapped

TF-004 Implement and maintain state Practice Question

A user wants to remove a specific resource from Terraform state without destroying the actual infrastructure. Which command should they use?

⚠ Common exam trap

HashiCorp often tests the distinction between state manipulation commands that affect only the state file versus commands that trigger actual infrastructure changes, so candidates may confuse `terraform state rm` with `terraform destroy` or `terraform taint`.

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 rm resource

The `terraform state rm` command is the correct choice because it removes a specified resource from the Terraform state file without making any API calls to the actual infrastructure provider. This allows the resource to be detached from Terraform management while leaving the real-world resource running, which is exactly what the user wants.

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 rm resource

    Why this is correct

    The `terraform state rm <address>` command is precisely designed to remove one or more resource instances from the Terraform state file. This operation updates the state to reflect that Terraform no longer manages the specified resource, but critically, it does not interact with the cloud provider or affect the actual infrastructure resource itself. The resource will continue to exist in the cloud, unmanaged by Terraform, making this the correct choice for decoupling a resource from state without destruction.

  • terraform taint resource

    Why it's wrong here

    The `terraform taint <address>` command marks a specific resource instance as "tainted" within the Terraform state. This action signals to Terraform that the next `terraform apply` operation should destroy and then recreate that particular resource, even if its configuration has not changed. Tainting a resource explicitly prepares it for replacement, which is fundamentally different from simply removing its entry from the state file while leaving the infrastructure intact.

  • terraform state mv resource

    Why it's wrong here

    The `terraform state mv <source_address> <destination_address>` command is used to move a resource or module from one address to another within the Terraform state file. This is typically employed when refactoring Terraform configurations, such as moving a resource into a module or renaming a resource block. While it modifies the state, it does not remove the resource's entry entirely; instead, it re-points Terraform's management to a new logical location for the existing resource.

  • terraform destroy -target=resource

    Why it's wrong here

    The `terraform destroy -target=<address>` command instructs Terraform to destroy the specified real-world infrastructure resource managed by the configuration. This command actively communicates with the cloud provider to deprovision the resource, and only *after* successful destruction is the resource's entry removed from the Terraform state. Its primary purpose is infrastructure removal, which is a much more impactful operation than merely detaching a resource from state management.

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.