How to destroy one specific resource from TF file in Terraform?

Terraform destroy is a command that allows you to destroy either a full stack (based on your TF files), or single resources, using the -target option. You can even do:

$ terraform state list
$ terraform destroy -target RESOURCE_TYPE.NAME
$ terraform destroy -target RESOURCE_TYPE.NAME -target RESOURCE_TYPE2.NAME
$ terraform state list

Option of skipping a resource while destroying terraform resources?

$ terraform state list
$ terraform destroy -target=RESOURCE_TYPE.NAME -target=RESOURCE_TYPE2.NAME
$ terraform state list

How to remove single resources, single instances of a resource, entire modules, and more items from the Terraform state?

# Remove a Resource
$ terraform state rm module.foo.packet_device.worker[0]

# Remove a Module
$ terraform state rm module.foo

How to delete all resources except one?

# list all resources
terraform state list

# remove that resource you don't want to destroy
# you can add more to be excluded if required
terraform state rm <resource_to_be_deleted> 

# destroy the whole stack except above resource(s)
terraform destroy 
Rajesh Kumar
Follow me
Latest posts by Rajesh Kumar (see all)