If you have Virtual Machines in your Azure subscription, that don’t require 24×7 uptime, this is the blog post for you.
My blog post, where I hope to provide a detailed step by step, is based on the Microsoft official article Start/Stop VMs during off-hours solution in Azure Automation. I highly recommend that you read that article, since this post is more focused on the execution and not necessarily on a detailed explanation of every component.
So what’s the goal here? To be able to, without human interaction, start and stop virtual machines in your Azure subscription, daily. Cool, right?
Before I continue and in case that all you need is to stop Virtual Machines, for that you can leverage a much simpler process, by configuring the “Auto-shutdown” option, under the “Operations” section of a Virtual Machine settings.
But if you need to do both, shutdown and boot up machines, then continue reading.
What are the prerequisites to configure this solution?
To be able to configure the solution to start and stop virtual machines, you need the following:
You can create those resources when you’re enabling the solution, or separately by adding new resources in the “All Resources” tab.
How do I configure the solution?
You have two easy ways of configuring the solution.
Add a new resource in the “All resources” tab
This is the ideal solution specially if you haven’t create the Automation account.
On the left hand side menu, browse to “All Resources”, click new and type “Start/Stop”. The solution would pop up for selection. Click “Create”.
Via your Azure Automation account
If you already have an automation account created, use it to access the Start/Stop VM solution.
Browse to the automation account and under “Related Resources” click “Start/Stop VM”. Then click “Learn more about and enable the solution”.
You will end up in the same creation page as shown in the option above.
Configure the solution
The step by step configuration of the solution is actually very simple. As noted in the begging of this post, all you need is to select an automation account, a log analytics workspace and configure the solution details.
First you start by selecting an existing or configuring a new Log Analytics workspace. If you create a new one, all you have to do is give it a name, associate it with a resource group (new or existing), select a location and for the Pricing tier keep the “Per GB”.
In the second step, you can select an existing or create a new automation account. If you create a new one, just select the name. The resource group and corresponding location will be locked to the one where the solution is being deployed. Also the Automation Account will be created as a “Run As Account”.
If you’re creating an automation account separately and you can’t see it for selection here, it might be because of several things, such as the account not being created as “Run As” (mandatory) or being in a resource group or location makes it unavailable.
Finally you can configure the most important, which is the solution parameters. Those include the following:
- Target resource group – Enter the name of the resource group(s) that you want to target. Names are case-sensitive. If you want to target all groups enter “*”. If you want to target multiple use the comma as separator between group names.
- VM Exlude List – Use this field to exclude any VM’s in your resource group that you don’t want the solution to affect. It’s important to understand that this solution will by default target the entire resource group, unless you exclude VMs here.
- Daily Start and Stop Time – select the time that you want your VMs to be boot up and shut down, everyday.
- Email functionality – if you want to receive an email notification each time an action is taken towards a VM (i.e shutdown), select yes and enter the email address you want to get the email on (multiple emails separated by commas).
How do I check if it worked?
Browse to your Automation Account and under “Process Automation > Jobs”.
Click on the latest job to see more details.
You can browse between tabs to check the details of the job execution. Pay special attention the the “All Logs” tab, where you can see the actions executed, number of errors and number of warnings.
The bottom line
Personally, I love this solution. It’s easy to deploy and saves me a ton of my Azure monthly credit.
You can go beyond what I showed you in this post and manually edit the job details, to do things like create an end date for the job, but this turn key Azure solution, although not extremely flexible (i.e targets entire workgroups and it’s tricky to specify exceptions in workgroups with a large number of VMs: it’s designed for daily boot up and shut down actions, etc), it’s very useful. 5 stars!!
Use it and give your own opinion. As always, any questions let me know.