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 destroyDo 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 completeApply 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...