Sometimes a resource should stay in the cloud but leave your code — handed to another team, or managed elsewhere. Deleting the resource block would destroy it. There are two safe ways out.
tofu state rm -dry-run module.foo.aws_instance.worker
tofu state rm module.foo.aws_instance.worker
Removes the binding from state; the real object keeps running. -dry-run lists what would be removed. Addresses can target a resource, a module, or a single count / for_each instance.
Catch: if the resource block is still in your code, the next plan proposes to create a new object — which may fail on name conflicts. Remove the block from code too.
removed {
from = aws_instance.worker
lifecycle {
destroy = false
}
}
Declares in code that the resource should be forgotten, and destroy = false keeps the object running. It goes through review and a plan like any other change.
-dry-run first and a state backup.Examples use OpenTofu (tofu); in Terraform the commands start with terraform. Check the documentation for your version before relying on a feature.
Tell us what you are trying to fix. No preparation needed.