2014-07-28 19:43:00 +02:00
---
layout: "intro"
page_title: "Destroy Infrastructure"
sidebar_current: "gettingstarted-destroy"
2014-10-22 05:21:56 +02:00
description: |-
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.
2014-07-28 19:43:00 +02:00
---
# 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.
2017-10-30 21:33:27 +01:00
## Destroy
2014-07-28 19:43:00 +02:00
2017-10-30 21:33:27 +01:00
Resources can be destroyed using the `terraform destroy` command, which is
similar to `terraform apply` but it behaves as if all of the resources have
been removed from the configuration.
2014-07-28 19:43:00 +02:00
```
2017-10-30 21:33:27 +01:00
$ terraform destroy
2017-04-06 20:02:56 +02:00
# ...
2014-07-28 19:43:00 +02:00
- aws_instance.example
```
2018-03-02 18:16:01 +01:00
The `-` prefix indicates that the instance will be destroyed. As with apply,
2017-10-30 21:33:27 +01:00
Terraform shows its execution plan and waits for approval before making any
changes.
2014-07-28 19:43:00 +02:00
2017-10-30 21:33:27 +01:00
Answer `yes` to execute this plan and destroy the infrastructure:
2014-07-28 19:43:00 +02:00
```
2017-10-30 21:33:27 +01:00
# ...
2014-07-28 19:43:00 +02:00
aws_instance.example: Destroying...
Apply complete! Resources: 0 added, 0 changed, 1 destroyed.
2017-04-06 20:02:56 +02:00
# ...
2014-07-28 19:43:00 +02:00
```
2017-10-30 21:33:27 +01:00
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.
2014-07-28 19:43:00 +02:00
## Next
2015-04-20 06:56:03 +02:00
You now know how to create, modify, and destroy infrastructure
from a local machine.
2014-07-28 19:43:00 +02:00
2017-03-15 01:41:31 +01:00
Next, we move on to features that make Terraform configurations
slightly more useful: [variables, resource dependencies, provisioning,
and more](/intro/getting-started/dependencies.html).