Terraform state rm

We know that the point of state in Terraform is to bind a resource in your source code to resources in your cloud provider, this makes state rm is a bit of an odd command in Terraform. If removing a resource in your cloud provider is required, then removing the corresponding binding in Terraform will have that affect, as well as updating state accordingly.

There are occasions however when you may need to remove a resource from Terraform state whilst leaving it in place with your provider. For example you may have used the Terraform import function to bring a particular resource under IaC, this action may not have gone to plan and the result may not be satisfactory. Simply removing the block from your code will of course delete the resource in your cloud provider because it already exists in state.

This is where state rm comes in. Remove the resource from your code and leave it untouched in your cloud provision.