Introduction

In this post, we will read about an Azure Logic App solution which allows us to Start and Deal locate 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 we 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 we can deploy this solution by following the steps below.

Start-on an Azure VM

Step 1. Add a Recurrence trigger


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



Step 2. Add an HTTP POST action

Next, we 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 we 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 we add a Recurrence trigger to start the VM every day at 17:00 in the evening.



Step 2. Add an HTTP POST action


 Next, we 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 we 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).

  


I hope it will helpful for you ..........