Logic Apps to Automate Cost Savings
Controlling costs in Azure
Controlling the costs in Azure can be a challenge, Microsoft have done a brilliant job of showing how you spend your money with their cost analysis features however there appears to be some gaps in the Azure Advisor to some of the resources. One of these omissions is Unused Public IP Addresses and Unattached disks only show up after 30 days of being unattached. The alerts in Azure Advisor I’ve also found to be hit and miss when new resources are being added into an already existing recommendation as well as they alert is on “New recommendation”.
Logic Apps
I’ve looked at creating 2 Logic Apps that in this example allow you log the unused resources into Log Analytics, however you could do something more interesting like Add a Tag to the resource so if it runs twice it can delete the resources automatically or send an approval e-mail before deleting etc maybe even just raise an ticket in your service desk software.
The Logic apps uses the ARM connecter using a Managed Identity so the Logic App will need to be given permissions over the relevant resources. The Logic app code can be found in my github here.
Unattached Public IP Address Flow Chart
Unattached Disks Flow Chart
Assign Logic App Permissions to Subscription
After the logic apps are created you will need to assign them some RBAC roles, I suggest the PIP Logic App holds Network Contributor
and the disk to hold Virtual Machine Contributor
.