Which command should you use to tell Terraform to no longer manage the resource?

Prepare for the HashiCorp Terraform Associate Exam with quizzes, flashcards, and multiple-choice questions. Each question includes hints and explanations. Boost your confidence and ace your exam!

Multiple Choice

Which command should you use to tell Terraform to no longer manage the resource?

Explanation:
Detaching a resource from Terraform’s management is done by removing it from the state. The correct approach is to run terraform state rm aws_instance.ubuntu[1]. This command deletes the resource’s entry from Terraform’s state file, so Terraform will no longer track or manage that resource in future operations. It’s important to note that this does not delete the actual resource in the cloud provider—it simply forgets about it. If the resource still exists and the configuration still defines it, a subsequent apply could recreate it because Terraform no longer has a record of its prior existence. If your goal is to also remove the resource from the cloud, you’d separately delete it (for example, with terraform destroy targeting that resource) or remove it from the configuration and then apply after removing from state.

Detaching a resource from Terraform’s management is done by removing it from the state. The correct approach is to run terraform state rm aws_instance.ubuntu[1]. This command deletes the resource’s entry from Terraform’s state file, so Terraform will no longer track or manage that resource in future operations.

It’s important to note that this does not delete the actual resource in the cloud provider—it simply forgets about it. If the resource still exists and the configuration still defines it, a subsequent apply could recreate it because Terraform no longer has a record of its prior existence.

If your goal is to also remove the resource from the cloud, you’d separately delete it (for example, with terraform destroy targeting that resource) or remove it from the configuration and then apply after removing from state.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy