You need to remove a specific resource from Terraform state management without destroying the actual cloud resource. Which command accomplishes this?

Direct Answer (Verified)Reviewed by Sunny (Senior Cloud Engineer)

Correct Answer: `terraform state rm aws_instance.web`

`terraform state rm` removes a resource from the state file without affecting the underlying infrastructure. This is useful when you want Terraform to stop managing a resource (e.g...

Real Exam Scenario

You need to remove a specific resource from Terraform state management without destroying the actual cloud resource. Which command accomplishes this?

✓ Correct Answer & Explanation

Correct Answer

`terraform state rm aws_instance.web`

Why This Answer Is Correct

`terraform state rm` removes a resource from the state file without affecting the underlying infrastructure. This is useful when you want Terraform to stop managing a resource (e.g., before importing it elsewhere or converting it to unmanaged). `destroy -target` actually terminates the resource. `taint` marks it for recreation. `import` does the opposite — it adds an existing resource to state.