What is the command to destroy infrastructure in Terraform?

The ‘destroy’ command

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.

Syntax

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.

Targeted destruction

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>

Alternate command

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.

Following steps

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

Copyright ©2025 Educative, Inc. All rights reserved