For a tester or a developer, the cost for a lab virtual machine is not something negligible because it has a daily cost. The solution to this problem is the Start/Stop VMs Automation in Azure.
Before we start, we should know.
- The Automation Account must be in the same Subscription with the Virtual Machines
- The solution must be deployed in any region that Log Analytics workspace is supported
- The Azure Run As Account must be a Service Administrator
Search for the Solution
The first we should do is to search for the [Start/Stop VMs during off-hours] solution.
So the steps are:
- Search for the [Start/Stop VMs during off-hours] solution
- Select the result [Start/Stop VMs during off-hours]
- Click Create to begin the solution deployment
Create Log Analytics Workspace
The first from the next steps is to Create a Log analytics workspace if it doesnt already exist.
- From the Add Solution blade, select *Workspace
- We don’t have an OMS Workspace, so we click Create New Workspace to create a new one.
- In the new blade called Log analytics workspace fill in all the needed information for the deployment, as the below image shows.
Setting | Value |
OMS Workspace | Type a name for the OMS Workspace |
Subscription | Select an Azure Subscription |
Resource Group | Select an existing or create a new Resource Group |
Location | Select a Location for the resources |
Create Automation Account
At the next step, we must create an Automation account. This account will be the one that the solution will run.
- Select *Automation account
- We don’t have any automation account to select, so we must create a new by clicking the Create an Automation account link
- In the Add Automation Account blade, we type all the necessary information for the automation account and we click Create.
Setting | Value |
Name | Type the Automation Account name |
Subscription | Select an Azure Subscription |
Resource Group | Select the Resource Group that we created in the previous step |
Set-up the Configuration Parameters
The last step to begin the deployment is to set-up to *configure parameters of the solution.
- Select the *configure parameters
- Fill in the necessary details into the Parameters blade, and click Create.
Setting | Value |
Vm runbook – Target ResourceGroup Names(string) | By default all resource group in the subscription will be included, else type the resource group that contains the Virtual Machines. |
Vm runbook – VM Exclude List (string) | The default value is none, type the VM names to be excluded from the management operation. Separate names by using comma(,). |
Schedule – Daily Start Time | Enter time for starting VMs by resource group. Schedule will be reflected as UTC in the automation account. |
Schedule – Daily Stop Time | Enter time for stoping VMs by resource group. Schedule will be reflected as UTC in the automation account. |
Email functionality – Receive Email Notifications (string) | Azure Monitor features are used to send email notifications, Select Yes/No to enable or disable this |
Email functionality – Email Addresses (string) | Enter the recipients of the email. Separate names by using comma(,) |
The Runbook
The Runbook that is used to Start and Stop Virtual Machine(s) is the ScheduledStartStop_Parent.
Set Schedules
From the Runbook left blade Resources – Schedules, we can view the active Schedules (Start and Stop the VM) or we can Add a new schedule by clicking “+ Add a schedule“.
Add a New schedule
If there is a need to create a new schedule click the button “+ Add a schedule”
Schedule
On this step select an existing schedule or create a new one. In the image below there is an existing Schedule to Start Virtual Machine.
Parameters and run settings
At the ‘parameters and run settings’ step type Action, VM name and click OK.
Test The Runbook
We can also test the runbook to see if there is an error on the executed actions using the Test Pane.
To begin Test Pane select Edit
In the next step select Test pane
Type the Parameters as the image below shows, and click Start
The Runbook Test begin and we are able to view the results and the error messages as the next image shows.
Completed
Logging in to Azure... Environments ------------ {[AzureChinaCloud, AzureChinaCloud], [AzureCloud, AzureCloud], [AzureGermanCloud, AzureGermanCloud], [AzureUSGovernme... Authenticating Classic RunAs account Get connection asset: AzureClassicRunAsConnection Getting the certificate: AzureClassicRunAsCertificate Authenticating to Azure with certificate. Runbook Execution Started... VM List is given to take action (Exclude list will be ignored)... The current action is start Calling the ScheduledStartStop_Child wrapper (Action = start)... Performing the schedule start for the VM : VMName using AzureRM ~Attempted the start action on the following VMs: VMName Runbook Execution Completed...