One of the best perks of moving your infrastructure to the cloud is the ability to only pay for the resources you use. When using Virtual Machines that usage can be even further limited to servers that stay on only when you need them (business hours or nightly data runs) and then shut down to minimize costs. Here is a quick guide on how to Auto Spin up and Down Azure Virtual Machines (VM).
Configuration of Automation Accounts
- From the Azure Portal, navigate to “Automation Accounts”
- Click “Add” to create a new account and fill in the basic information. Any name, subscription resource group and location will do but keeping these inline with where your VM is located will make it easier. Keep “Create Azure Run As Account” Selected as “Yes” and select “Create” to create.
From your new Automation account, select “Runbooks”
- We will now “Browse Gallery” and from the gallery section, select “Start Azure V2 VMs” followed by “Import” on the next screen
- Do the same exercise with “Stop Azure V2 Machine”. Both will now be available in the runbook’s menu.
From the main runbook screen, you can now click on “Edit” and “publish”
Scheduling the Jobs
- Click on “StartAzureV2Vm” to go to details. From the menu on the right select “Schedules” followed by add schedules.
- Select “Link a schedule to your runbook” and select “Create a new schedule”. Give the schedule a name, description and a start date. Select “Recurring” for recurrence so that it runs daily. Leave “Set expiration” to “No”
- Select “Parameters and run settings” and “Configure parameters and run settings”. In the details, use the name of the resource group name your VM is located in and the exact VM name of your virtual machine. Select ok to save and close the windows.
You may require to edit and publish the runbook again but if not you can manually run the job to test or wait until the schedule is ready. Repeat the same exercise for the Shutdown VM job giving it a time later then the activation schedule previously created to Auto Spin up and Down Azure Virtual Machines (VM).
For more information, please see the official documentation from Microsoft.
https://docs.microsoft.com/en-us/azure/automation/automation-runbook-types