terraform/website/docs/cli/commands/destroy.html.md

49 lines
1.5 KiB
Markdown
Raw Normal View History

2014-10-01 07:08:32 +02:00
---
layout: "docs"
page_title: "Command: destroy"
sidebar_current: "docs-commands-destroy"
2014-10-22 05:21:56 +02:00
description: |-
The `terraform destroy` command is a convenient way to destroy all objects
managed by a particular Terraform configuration.
2014-10-01 07:08:32 +02:00
---
# Command: destroy
The `terraform destroy` command is a convenient way to destroy all remote
objects managed by a particular Terraform configuration.
While you will typically not want to destroy long-lived objects in a production
environment, Terraform is sometimes used to manage ephemeral infrastructure
for development purposes, in which case you can use `terraform destroy` to
conveniently clean up all of those temporary objects once you are finished
with your work.
2014-10-01 07:08:32 +02:00
## Usage
main: new global option -chdir This new option is intended to address the previous inconsistencies where some older subcommands supported partially changing the target directory (where Terraform would use the new directory inconsistently) where newer commands did not support that override at all. Instead, now Terraform will accept a -chdir command at the start of the command line (before the subcommand) and will interpret it as a request to direct all actions that would normally be taken in the current working directory into the target directory instead. This is similar to options offered by some other similar tools, such as the -C option in "make". The new option is only accepted at the start of the command line (before the subcommand) as a way to reflect that it is a global command (not specific to a particular subcommand) and that it takes effect _before_ executing the subcommand. This also means it'll be forced to appear before any other command-specific arguments that take file paths, which hopefully communicates that those other arguments are interpreted relative to the overridden path. As a measure of pragmatism for existing uses, the path.cwd object in the Terraform language will continue to return the _original_ working directory (ignoring -chdir), in case that is important in some exceptional workflows. The path.root object gives the root module directory, which will always match the overriden working directory unless the user simultaneously uses one of the legacy directory override arguments, which is not a pattern we intend to support in the long run. As a first step down the deprecation path, this commit adjusts the documentation to de-emphasize the inconsistent old command line arguments, including specific guidance on what to use instead for the main three workflow commands, but all of those options remain supported in the same way as they were before. In a later commit we'll make those arguments produce a visible deprecation warning in Terraform's output, and then in an even later commit we'll remove them entirely so that -chdir is the single supported way to run Terraform from a directory other than the one containing the root module configuration.
2020-09-02 00:45:12 +02:00
Usage: `terraform destroy [options]`
2014-10-01 07:08:32 +02:00
This command is just a convenience alias for the following command:
```
terraform apply -destroy
```
For that reason, this command accepts most of the options that
[`terraform apply`](./apply.html) accepts, although it does
not accept a plan file argument and forces the selection of the "destroy"
planning mode.
2014-10-01 07:08:32 +02:00
You can also create a speculative destroy plan, to see what the effect of
destroying would be, by running the following command:
```
terraform plan -destroy
```
2015-03-27 23:24:15 +01:00
This will run [`terraform plan`](./plan.html) in _destroy_ mode, showing
you the proposed destroy changes without executing them.
2015-03-27 23:24:15 +01:00
-> **Note:** The `-destroy` option to `terraform apply` exists only in
Terraform v1.0 and later. For earlier versions, you _must_ use
`terraform destroy` to get the effect of `terraform apply -destroy`.