Virtual machines in a cloud are most of their time not productively and waiting for some jobs to do. Especially during off-hours when the offices are closed and the people are sleeping at their homes.
Azure Virtual Machines have the capability to Auto-shutdown at a specific time of the day. This can be configured in the Azure Portal but there is no easy way to configure it to Auto-startup at a specific time of the day.
There is a very large and complex solution available from Microsoft to schedule starting and stopping Azure Virtual Machines based on a Azure Automation Account. Very nice solution but for my problem too complex and too much configuration to get it working.
Azure Logic App Solution
Logic App Recurrence Trigger
The Logic App is using the Recurrence trigger to start every day at (for example) 6:00 o’ clock.
Logic App HTTP action
There is a command to start an Azure Virtual Machine using the Azure REST API. This command can be triggered by a Logic App using the HTTP Action. The command to start a Virtual Machine is the following:
Don’t forget to set the Authentication to
Enable Managed Identity on the Logic App
Not everybody is allowed to start or stop a Virtual Machine in Azure. We can set the Authentication to Managed Identity.
Giving the identity of the Logic App the build-in role Virtual Machine Contributor allows the Logic App to start/stop the Virtual Machine.
Using the Auto-shutdown functionality of the Virtual Machine in the Azure Portal to stop the Virtual Machine at the end of the day and the Logic App to start the Virtual Machine in the morning we reduce the cost of this Virtual Machine.