Courseiva
Understand Terraform basicsmediumMultiple ChoiceObjective-mapped

TF-004 Understand Terraform basics Practice Question

Exhibit

terraform state list
aws_instance.web
aws_instance.db
aws_eip.web_ip
aws_s3_bucket.logs

Refer to the exhibit. An engineer runs terraform state list and sees these resources. The engineer wants to remove the aws_eip.web_ip resource from state without destroying the actual resource. Which command should be used?

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 aws_eip.web_ip

To remove a resource from state without destroying it, use terraform state rm.

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 aws_eip.web_ip

    Why this is correct

    The `terraform state rm` command is specifically designed to remove one or more resources from the Terraform state file without interacting with the actual cloud infrastructure. This operation is crucial when a resource is no longer intended to be managed by Terraform but should persist in the cloud, or when the state file needs manual correction due to an out-of-band change. It ensures that subsequent `terraform plan` or `apply` operations will no longer consider this resource as part of the managed configuration.

  • terraform destroy -target=aws_eip.web_ip

    Why it's wrong here

    The `terraform destroy` command, even when used with the `-target` flag, is intended for the complete removal of the specified resource from both the Terraform state and the actual cloud provider. This action would permanently delete the `aws_eip.web_ip` from AWS, which directly contradicts the objective of merely removing it from state while preserving the real resource. Therefore, it is an inappropriate command for this specific state manipulation task.

  • terraform refresh -target=aws_eip.web_ip

    Why it's wrong here

    The `terraform refresh` command updates the Terraform state file to reflect the current real-world state of the infrastructure. While it synchronizes the state, it does not provide a mechanism to explicitly remove a resource from the state file while leaving the actual resource untouched. Its primary purpose is to detect and update attribute changes or remove resources from state that have been manually deleted from the cloud, not to selectively unmanage an existing resource.

  • terraform import aws_eip.web_ip <id>

    Why it's wrong here

    The `terraform import` command serves the opposite purpose of removing a resource from state; it is used to bring existing, unmanaged infrastructure resources into Terraform's state file. By importing, an existing `aws_eip` would be added to the state, allowing Terraform to manage it going forward. This command is entirely unsuitable for the task of disassociating a resource from Terraform management while keeping it deployed.

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 →

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.