Destroying the Resources

Learn how to destroy all the resources that we created in Azure.

Destroying the resources

We’re (almost) finished with the quick exploration of Terraform using AKS as an example. We saw how to add and change resources, and the only thing missing is to see how to destroy them.

If we want to delete some of the resources, all we’d have to do is remove their definitions and execute terraform apply. However, in some cases, we might want to destroy everything. There’s a command for that as well. However, in this specific case, we might not want to destroy everything.

We need to keep the storage where the Terraform state is stored. That will allow us to re-create the same cluster for the rest of the exercises. If we’re using AWS or GCP, we would simply execute terraform destroy because those two don’t allow us to destroy storage if there are files inside it. Or, to be more precise, that’s the default behavior, and we need to specify explicitly that we want to destroy storage even if it contains files by setting the argument force_destroy to true.

Get hands-on with 1200+ tech skills courses.