terraform destroy will tear down the entire stack related to some terraform code.
Nevertheless, typically you may solely need to take away a selected piece of your infrastructure.
To do that, you should use the
terraform destroy -target object.
Step 1 – Listing the State
Get an inventory of all of the assets from the state:
terraform state record #information.aws_ami.webserver_ami #aws_autoscaling_group.asg-web #random_string.rand3 #...
Step 2 – Take away a Particular Useful resource
terraform destroy -target and cross a useful resource from the
state record above:
terraform destroy -target aws_autoscaling_group.asg-web -auto-approve
We additionally added a
-auto-approve within the above command to mechanically delete the useful resource with out prompting us for affirmation.