Virtual Event
Join us for the next HashiConf Digital October 12-15, 2020 Register for Free

Get Started - AWS

Destroy Infrastructure

We've now seen how to build and change infrastructure. Before we move on to creating multiple resources and showing resource dependencies, we're going to go over how to completely destroy the Terraform-managed infrastructure.

Destroying your infrastructure is a rare event in production environments. But if you're using Terraform to spin up multiple environments such as development, test, QA environments, then destroying is a useful action.


The terraform destroy command terminates resources defined in your Terraform configuration. This command is the reverse of terraform apply in that it terminates all the resources specified by the configuration. It does not destroy resources running elsewhere that are not described in the current configuration.

$ terraform destroy

# ...
  # aws_instance.example will be destroyed
  - resource "aws_instance" "example" {
      - ami                          = "ami-b374d5a5" -> null
# ...

The - prefix indicates that the instance will be destroyed. As with apply, Terraform shows its execution plan and waits for approval before making any changes.

Answer yes to execute this plan and destroy the infrastructure.

# ...
aws_instance.example: Destroying... [id=i-0589469dd150b453b]

Destroy complete! Resources: 1 destroyed.
# ...

Just like with apply, Terraform determines the order in which things must be destroyed. In this case there was only one resource, so no ordering was necessary. In more complicated cases with multiple resources, Terraform will destroy them in a suitable order to respect dependencies, as we'll see later in this guide.