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
Terraform Basic Tutorial with Demo by Piyush 2020
Terraform Fundamental Tutorials by Harish in 2020
Terraform Fundamental Tutorial By Guru in 2020 Part-1
Terraform Fundamental Tutorial By Guru in 2020 Part-2
Terraform Fundamental Tutorial By Guru in 2020 Part-3
Terraform Fundamental Tutorial By Guru in 2020 Part-4
Terraform Fundamental Tutorial By Guru in 2020 Part-5
Terraform Advance Tutorial for Beginners with Demo 2020 — By DevOpsSchool
Latest posts by Rajesh Kumar (see all)
- Installing Jupyter: Get up and running on your computer - November 2, 2024
- An Introduction of SymOps by SymOps.com - October 30, 2024
- Introduction to System Operations (SymOps) - October 30, 2024