TA-002-P · Question #82
A fellow developer on your team is asking for some help in refactoring their Terraform code. As part of their application's architecture, they are going to tear down an existing deployment managed by
The correct answer is B. terraform state rm aws_instance.ubuntu[1]. To tell Terraform to stop managing a specific resource without destroying it, the terraform state rm command should be used. This command removes the resource's entry from the state file, allowing the resource to persist in the cloud while being ignored by future Terraform operat
Question
A fellow developer on your team is asking for some help in refactoring their Terraform code. As part of their application's architecture, they are going to tear down an existing deployment managed by Terraform and deploy new. However, there is a server resource named aws_instance.ubuntu[1] they would like to keep to perform some additional analysis. What command should be used to tell Terraform to no longer manage the resource?
Options
- Aterraform apply rm aws_instance.ubuntu[1]
- Bterraform state rm aws_instance.ubuntu[1]
- Cterraform plan rm aws_instance.ubuntu[1]
- Dterraform delete aws_instance.ubuntu[1]
How the community answered
(19 responses)- A5% (1)
- B89% (17)
- D5% (1)
Why each option
To tell Terraform to stop managing a specific resource without destroying it, the `terraform state rm` command should be used. This command removes the resource's entry from the state file, allowing the resource to persist in the cloud while being ignored by future Terraform operations.
`terraform apply` is used to create, update, or destroy infrastructure based on configuration changes; `rm` is not a valid subcommand for `apply`.
The `terraform state rm` command is used to remove a specific resource from the Terraform state file without destroying the actual infrastructure resource. This allows Terraform to "forget" about a resource, letting it persist in the cloud while no longer being managed by Terraform.
`terraform plan` is used to show what changes Terraform plans to make, and `rm` is not a valid subcommand for `plan`.
`terraform delete` is not a valid Terraform CLI command; `terraform destroy` is used to tear down resources.
Concept tested: Removing resources from Terraform state
Source: https://developer.hashicorp.com/terraform/cli/commands/state/rm
Topics
Community Discussion
No community discussion yet for this question.