Destroying infrastructure with Terraform is as easy as or even easier than creating it. All you need to do is to run the terraform destroy
command, as shown here:
$> terraform destroy Do you really want to destroy? Terraform will delete all your managed infrastructure. There is no undo. Only 'yes' will be accepted to confirm. Enter a value:
Terraform is nice enough to ask you for a confirmation, in case you typed the terraform destroy
command by accident:
aws_instance.hello-instance: Refreshing state... (ID: i-06f88fe6a2b4307b8) aws_instance.hello-instance: Destroying... aws_instance.hello-instance: Still destroying... (10s elapsed) aws_instance.hello-instance: Still destroying... (20s elapsed) aws_instance.hello-instance: Destruction complete Apply complete! Resources: 0 added, 0 changed, 1 destroyed.
If we want to get rid of only one particular resource from our template, we don't need to run the terraform destroy
command. We could simply remove this resource from template.tf
, and the next terraform apply
command will figure out that you don't need this resource any more and destroy it. Try it yourself, by first running the terraform apply
command to create the instance again, then removing the instance from template.tf
and then plan and apply again. In the next chapter, we won't need this particular instance any longer.
52.15.59.163