My first look into Azure Automation Accounts with VM On/Off Runbooks
Whilst moving to Azure, I found a number of VMs that I couldn’t get off, not yet at least! Building dev and test environments meant that I only needed these VMs to run for about 10 hours a day, 5 days a week. (Everybody has flexible working hours right?)
The old way….
Azure used to have a little setting that simply turned off the VM at a specified time each day, great until the next morning when your CI pipeline tried to deploying to it and you realised it was still turned offline!
The new way…
Azure Automation! Thankfully Microsoft have made this nice and simple for us to start learning Azure Automation with some pre-built Runbooks for turning our VMs on and off on schedules.
Start by creating a new automation account, check the pricing details to make sure you’re not caught out. Once created scroll down to the option called Start/Stop VM
Follow the setup guide, specify the Resource Group your VMs are in that you want to turn on and off (I left it at the default of all) and set any VM exclusions. Once created you can see your Runbooks like below.
The highlighted runbook, ScheduledStartStop_Parent, is the parent scheduled runbook where you can modify the schedule beyond the simple first setup options. I specified ours to turn on at 7:30AM Mon-Fri (Some of the team start at 8AM so I wanted to make sure all VMs were running before anybody got in)
Once finished come your set scheduled times the automation magic will happen!
Couple of other notes:
- To change your resource groups / VM exclusion list go to the automation account and select the variables blade. You’ll see the options in the variable list
- Once your schedule kicks in, you’ll be placed into a queue waiting for Azure resource to become available to execute the runbook, I’ve found this can take a few minutes.
- There are loads more options to explore with these runbooks, for example if you have a domain controller that needs to be online before other VMs you can specify the order in which the VMs come up. Very cool! Microsoft have documented all the options here: https://docs.microsoft.com/en-us/azure/automation/automation-solution-vm-management