github.com/ezbercih/terraform@v0.1.1-0.20140729011846-3c33865e0839/website/source/intro/getting-started/destroy.html.md (about) 1 --- 2 layout: "intro" 3 page_title: "Destroy Infrastructure" 4 sidebar_current: "gettingstarted-destroy" 5 --- 6 7 # Destroy Infrastructure 8 9 We've now seen how to build and change infrastructure. Before we 10 move on to creating multiple resources and showing resource 11 dependencies, we're going to go over how to completely destroy 12 the Terraform-managed infrastructure. 13 14 Destroying your infrastructure is a rare event in production 15 environments. But if you're using Terraform to spin up multiple 16 environments such as development, test, QA environments, then 17 destroying is a useful action. 18 19 ## Plan 20 21 For Terraform to destroy our infrastructure, we need to ask 22 Terraform to generate a destroy execution plan. This is a special 23 kind of execution plan that only destroys all Terraform-managed 24 infrastructure, and doesn't create or update any components. 25 26 ``` 27 $ terraform plan -destroy -out=terraform.tfplan 28 ... 29 30 - aws_instance.example 31 ``` 32 33 The plan command is given two new flags. 34 35 The first flag, `-destroy` tells Terraform to create an execution 36 plan to destroy the infrastructure. You can see in the output that 37 our one EC2 instance will be destroyed. 38 39 The second flag, `-out` tells Terraform to save the execution plan 40 to a file. We haven't seen this before, but it isn't limited to 41 only destroys. Any plan can be saved to a file. Terraform can then 42 apply a plan, ensuring that only exactly the plan you saw is executed. 43 For destroys, you must save into a plan, since there is no way to 44 tell `apply` to destroy otherwise. 45 46 ## Apply 47 48 Let's apply the destroy: 49 50 ``` 51 $ terraform apply terraform.tfplan 52 aws_instance.example: Destroying... 53 54 Apply complete! Resources: 0 added, 0 changed, 1 destroyed. 55 56 ... 57 ``` 58 59 Done. Terraform destroyed our one instance, and if you run a 60 `terraform show`, you'll see that the state file is now empty. 61 62 For this command, we gave an argument to `apply` for the first 63 time. You can give apply a specific plan to execute. 64 65 ## Next 66 67 You now know how to create, modify, and destroy infrastructure. 68 With these building blocks, you can effectively experiment with 69 any part of Terraform. 70 71 Next, we move on to features that make Terraform configurations 72 slightly more useful: [variables, resource dependencies, provisioning, 73 and more](/intro/getting-started/dependencies.html).