In the 0.10 release we added an opt-in mode where Terraform would prompt interactively for confirmation during apply. We made this opt-in to give those who wrap Terraform in automation some time to update their scripts to explicitly opt out of this behavior where appropriate. Here we switch the default so that a "terraform apply" with no arguments will -- if it computes a non-empty diff -- display the diff and wait for the user to type "yes" in similar vein to the "terraform destroy" command. This makes the commonly-used "terraform apply" a safe workflow for interactive use, so "terraform plan" is now mainly for use in automation where a separate planning step is used. The apply command remains non-interactive when given an explicit plan file. The previous behavior -- though not recommended -- can be obtained by explicitly setting the -auto-approve option on the apply command line, and indeed that is how all of the tests are updated here so that they can continue to run non-interactively.
2.0 KiB
layout | page_title | sidebar_current | description |
---|---|---|---|
intro | Destroy Infrastructure | gettingstarted-destroy | 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. |
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.
Destroy
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.
$ terraform destroy
# ...
- aws_instance.example
The -
prefix indicates that a 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...
Apply complete! Resources: 0 added, 0 changed, 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.
Next
You now know how to create, modify, and destroy infrastructure from a local machine.
Next, we move on to features that make Terraform configurations slightly more useful: variables, resource dependencies, provisioning, and more.