A terraform
project uses up system resources until it is terminated. The terraform destroy
command is used to destroy the project infrastructure and free up the allocated resources. terraform destroy
only destroys the infrastructure for the current project. There are no changes made to the resources allocations running elsewhere.
Following is the command:
terraform destroy <additional_options>
In the above command, the additional_options
argument can be replaced by several possible flags to gain further control over the terraform destroy
command functionality.
Just running terraform destroy
destroys the whole project infrastructure, releasing all resources. Sometimes you need to destroy just a select few resources, and for that, you can use the -target
flag. When used with the -target
flag, the terraform destroy
command takes the resource name as its input and destroys just that specific resource upon execution.
Following is how you would use it:
terraform destroy -target <resource_name>
The terraform destroy
command can be considered an alias for the terraform apply
command with the -destroy
flag.
terraform apply -destroy
This command runs terraform apply
in the destroy
planning mode.
After running either one of the commands above, terraform
proceeds to present a destruction plan, which shows you all the resources that will be destroyed. If you approve of this plan, terraform destroyed the stated resources. Otherwise, the destroy command does not get executed.
Free Resources