|
1 | | ---- |
2 | | -title: Start/Stop Azure VMs during off-hours — The Logic App Solution |
3 | | -date: 2019-12-28 00:00:00 +1000 |
4 | | -categories: Azure |
5 | | -tags: |
6 | | - - Azure |
7 | | - - Logic Apps |
8 | | - - Virtual Machines |
9 | | - - Automation |
10 | | -excerpt_separator: <!--more--> |
11 | | ---- |
12 | | - |
13 | | -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. |
14 | | - |
15 | | -<!--more--> |
16 | | - |
17 | | -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. |
18 | | - |
19 | | - |
20 | | - |
21 | | -There is a very large and complex solution available from Microsoft to schedule [starting and stopping Azure Virtual Machines](https://docs.microsoft.com/en-us/azure/automation/automation-solution-vm-management) based on a Azure Automation Account. Very nice solution but for my problem too complex and too much configuration to get it working. |
22 | | - |
23 | | -## Azure Logic App Solution |
24 | | - |
25 | | - |
26 | | - |
27 | | -### Logic App Recurrence Trigger |
28 | | - |
29 | | -The Logic App is using the Recurrence trigger to start every day at (for example) 6:00 o’ clock. |
30 | | - |
31 | | - |
32 | | - |
33 | | -### Logic App HTTP action |
34 | | - |
35 | | -There is a command to [start an Azure Virtual Machine](https://docs.microsoft.com/en-us/rest/api/compute/virtualmachines/start) 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: |
36 | | - |
37 | | -``` |
38 | | -https://management.azure.com/subscriptions/[guid-of-the-subscription]/resourceGroups/[name-of-the-resource-group]/providers/Microsoft.Compute/virtualMachines/[name-of-the-vm]/start?api-version=2019-03-01 |
39 | | -``` |
40 | | - |
41 | | -Don't forget to set the Authentication to `Managed Identity`. |
42 | | - |
43 | | - |
44 | | - |
45 | | -### Enable Managed Identity on the Logic App |
46 | | - |
47 | | -Not everybody is allowed to start or stop a Virtual Machine in Azure. We can set the Authentication to [Managed Identity](https://docs.microsoft.com/en-us/azure/active-directory/managed-identities-azure-resources/overview). |
48 | | - |
49 | | - |
50 | | - |
51 | | -Giving the identity of the Logic App the build-in role [Virtual Machine Contributor](https://docs.microsoft.com/en-us/azure/role-based-access-control/built-in-roles#virtual-machine-contributor) allows the Logic App to start/stop the Virtual Machine. |
52 | | - |
53 | | - |
54 | | - |
55 | | -Thats it! |
56 | | - |
57 | | -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. |
| 1 | +--- |
| 2 | +title: Start/Stop Azure VMs during off-hours — The Logic App Solution |
| 3 | +date: 2019-12-28 00:00:00 +1000 |
| 4 | +categories: Azure |
| 5 | +tags: |
| 6 | + - Azure |
| 7 | + - Logic Apps |
| 8 | + - Virtual Machines |
| 9 | + - Automation |
| 10 | +excerpt_separator: <!--more--> |
| 11 | +--- |
| 12 | + |
| 13 | +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. |
| 14 | + |
| 15 | +<!--more--> |
| 16 | + |
| 17 | +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. |
| 18 | + |
| 19 | + |
| 20 | + |
| 21 | +There is a very large and complex solution available from Microsoft to schedule [starting and stopping Azure Virtual Machines](https://docs.microsoft.com/en-us/azure/automation/automation-solution-vm-management) based on a Azure Automation Account. Very nice solution but for my problem too complex and too much configuration to get it working. |
| 22 | + |
| 23 | +## Azure Logic App Solution |
| 24 | + |
| 25 | + |
| 26 | + |
| 27 | +### Logic App Recurrence Trigger |
| 28 | + |
| 29 | +The Logic App is using the Recurrence trigger to start every day at (for example) 6:00 o’ clock. |
| 30 | + |
| 31 | + |
| 32 | + |
| 33 | +### Logic App HTTP action |
| 34 | + |
| 35 | +There is a command to [start an Azure Virtual Machine](https://docs.microsoft.com/en-us/rest/api/compute/virtualmachines/start) 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: |
| 36 | + |
| 37 | +``` |
| 38 | +https://management.azure.com/subscriptions/[guid-of-the-subscription]/resourceGroups/[name-of-the-resource-group]/providers/Microsoft.Compute/virtualMachines/[name-of-the-vm]/start?api-version=2019-03-01 |
| 39 | +``` |
| 40 | + |
| 41 | +Don't forget to set the Authentication to `Managed Identity`. |
| 42 | + |
| 43 | + |
| 44 | + |
| 45 | +### Enable Managed Identity on the Logic App |
| 46 | + |
| 47 | +Not everybody is allowed to start or stop a Virtual Machine in Azure. We can set the Authentication to [Managed Identity](https://docs.microsoft.com/en-us/azure/active-directory/managed-identities-azure-resources/overview). |
| 48 | + |
| 49 | + |
| 50 | + |
| 51 | +Giving the identity of the Logic App the build-in role [Virtual Machine Contributor](https://docs.microsoft.com/en-us/azure/role-based-access-control/built-in-roles#virtual-machine-contributor) allows the Logic App to start/stop the Virtual Machine. |
| 52 | + |
| 53 | + |
| 54 | + |
| 55 | +Thats it! |
| 56 | + |
| 57 | +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. |
0 commit comments