Decommissioning Azure resources
Just as automation allows us to provision resources at scale, it also enables us to efficiently decommission them when no longer needed. With Azure and Ansible, this process is simplified—by making a single API call with the appropriate parameters, we can delete all resources within a resource group. In this recipe, we will demonstrate how to destroy the resources you’ve provisioned by decommissioning the entire resource group. (Remember we mentioned that grouping resources under a resource group is a best practice? Here comes the why it is so.)
To accomplish this, we can use the azure_rm_resourcegroup Ansible module, which allows you to delete both the resources within a resource group and the resource group itself. Two key parameters must be specified to ensure a successful deletion:
- Set
stateto absent to indicate that the resource group should be deleted - Set the
force_delete_nonemptyparameter to yes to ensure...