Reading Time: 3 minutes

In this post, I will present an Azure Logic App solution to Start and Deallocate an Azure VM.

Prerequisites

  • A valid Azure subscription
  • Azure Compute APIs
  • Configure build-in roles to the Azure VM
  • Enable the Logic Apps System assigned managed identity*

* The image above shows how you can enable the managed identity on the logic app.

The solution

The solution includes two logic apps, one to starting the Azure VM and another to deallocate it.

Let us see now how you can deploy this solution by following the steps below.

Start-on an Azure VM

Step 1. Add a Recurrence trigger

At first step add a Recurrence trigger to start the VM every day at 9:00 in the morning.

Step 2. Add an HTTP POST action

Next, you add an HTTP POST action using the Azure REST API. This URI would be triggered, by the Logic App and the VM will start on.

Tip: To complete the URI POST request you need to know three values : subscriptionId, resourceGroupName, vmName

https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{vmName}/start?api-version=2020-06-01

After you complete the HTTP POST URI, with the correct value parameters, change the Authentication type to Managed Identity and then save the Logic App.

The Result (Start On  Azure VM)

The image below shows the final flow with the two steps (Recurrence trigger and HTTP action).

 

Deallocate an Azure VM

Step 1. Add a Recurrence trigger

At first step add a Recurrence trigger to start the VM every day at 17:00 in the evening.

Step 2. Add an HTTP POST action

Next, you add an HTTP POST action using the Azure REST API. This URI would be triggered, by the Logic App and the VM will start on.

Tip: To complete the URI POST request you need to know three values : subscriptionId, resourceGroupName, vmName

https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{vmName}/deallocate?api-version=2020-06-01

After you complete the HTTP POST URI, with the correct value parameters, change the Authentication type to Managed Identity and then save the Logic App.

The Result (Deallocate Azure VM)

The image below shows the final flow with the two steps (Recurrence trigger and HTTP action).

Share This