terraform destroy will tear down the whole stack associated to some terraform code.
However, sometimes you might only want to remove a specific piece of your infrastructure.
To do this, you can use the
terraform destroy -target object.
Step 1 – List the State
Get a list of all the resources from the state:
Step 2 – Remove a Specific Resource
terraform destroy -target and pass a resource from the
state list above:
We also added a
-auto-approve in the above command to automatically delete the resource without prompting us for confirmation.