Overview
Here I worked on governance and cost control in my Azure subscription. I assigned the built-in policy Require a tag on resources to my rg-rbac-lab resource group so that every resource must have the tag Environment=Lab. I then deployed an Ubuntu VM with its supporting resources and checked their compliance. Finally I created an Automation Account with a PowerShell runbook that shuts the VM down on a schedule.
What I set out to do
- Enforce a tagging rule on resources with Azure Policy.
- Check compliance in the portal, Azure CLI and PowerShell.
- Shut the VM down automatically on a schedule to control cost.
What I did
- I reviewed my subscription details with Azure CLI queries and JSON output.
- I assigned the tag policy to rg-rbac-lab requiring Environment=Lab.
- I deployed an Ubuntu VM with its network interface, NSG, virtual network and disk.
- I created the Automation Account aa-rbaclab-shutdown with a system-assigned managed identity. I gave the identity Virtual Machine Contributor on the VM only.
- I published the Shutdown-VM-Daily-UAE runbook with three daily schedules at 2:00 AM, 5:00 PM and 10:00 PM UAE time.
Screenshots
They are in the same order as in my repository. Click one to see it full size.
I painted over my Azure subscription ID in red. Everything else is as I captured it.
1. Subscription Login and OverviewShows the Azure CLI login, active account and subscription information. 2. Subscription JSON and CLI QueriesShows subscription information retrieved in JSON format and Azure CLI queries used to inspect subscription details. 3. Subscription and Resource Group GovernanceShows the subscription and resource group governance configuration. 4. VM Deployment SuccessShows the successful deployment of the virtual machine and its supporting Azure infrastructure. 5. VM Running OverviewShows the deployed virtual machine and its configuration in the Azure Portal. 6. Azure Policy Compliance DashboardShows the Azure Policy compliance dashboard and the compliance overview for the resource group. 7. Require a Tag PolicyShows the configured Require a tag on resources policy assignment and its compliance information. 8. Individual Resource ComplianceShows the individual resources evaluated against the Require a tag on resources policy, including their compliance results. 9. PowerShell Policy Compliance VerificationShows the use of PowerShell to retrieve and inspect Azure Policy compliance results. 10. Automated VM Shutdown SchedulesShows the three enabled daily shutdown schedules associated with the `Shutdown-VM-Daily-UAE` runbook, configured for 2:00 AM, 5:00 PM and 10:00 PM using Gulf Standard Time (UAE time). 11. Automated VM Shutdown VerificationShows the successful execution of the `Shutdown-VM-Daily-UAE` runbook, including the completed Azure Automation job and its execution details. The VM's final `PowerState/deallocated` state was independently verified using PowerShell.
How I tested it
- Compliance showed all five resources as compliant in the portal, Azure CLI and PowerShell.
- A runbook job completed and PowerShell showed the VM as deallocated.
Repository
My full notes and the original screenshots are on GitHub: azure-administrator-labs/04-azure-subscription-governance