How to Delete All Resources Except One in Terraform

If you need to delete all resources created by Terraform, except for a single, specific one, then you can do the following:

Step 1 – Get the current state list

terraform state list

Step 2 – Remove the exception resource

Remove the specific resource that you don’t want Terraform to track anymore.

terraform state rm <resource_to_be_removed>

Step 3 – Destroy the resources

terraform destroy