Search
StarWind is a hyperconverged (HCI) vendor with focus on Enterprise ROBO, SMB & Edge

How to Start Azure Virtual Machines using Azure Logic Apps?

  • May 27, 2020
  • 7 min read
IT Production Manager. Nicolas is primarily focused on Microsoft technologies, he is a Microsoft MVP in Cloud and Datacenter Management.
IT Production Manager. Nicolas is primarily focused on Microsoft technologies, he is a Microsoft MVP in Cloud and Datacenter Management.

Azure Logic Apps

From the Azure Portal, you can easily enable Auto-shutdown on the Virtual Machine Properties page in order to stop your Virtual Machines on a specific schedule, but you can not schedule the Virtual Machines to start. Auto-Shutdown is very interesting to reduce Azure costs for non-production environments.

Virtual Machine Properties

To be able to automatically start your virtual machine on a specific time you can use the Automation account by creating runbooks, but you can also use Logic Apps if you do not want to use PowerShell.

In this article, I will describe how to start a Virtual Machine using Azure Logic Apps, but you can also use Logic Apps to stop Virtual Machines.

Let’s start by creating a Logic Apps instance. Open the Azure Portal, navigate to “Logic Apps” and click “Add

Сreating a Logic Apps

Enter the name of your Logic Apps and click “Create

Logic Apps basics

The Logic Apps designer will appear. First, add the “Recurrence” trigger in order to start this instance on a specific schedule.

Logic Apps designer

You can schedule the instance depending your needs. In this example, I configured the recurrence every day at 07:00 AM:

Recurrence

Next, we add a new step called “HTTP”.

Virtual Machines can be started using the Azure API. The following documentation describes how to start a Virtual Machine:
https://docs.microsoft.com/en-us/rest/api/compute/virtualmachines/start

We must use the HTTP action with the POST method:

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

Replace the following items:

  • Subscription ID
  • Resource Group Name
  • VM Name

We can enable authentication at this step. Add Authentication type named “Managed Identity”:

Managed Identity

Validate the Logic Apps, and go to the “Identity” tab to enable the following setting:

“Identity” tab

When you will save the configuration, a pop-up will explain that your Logic Apps will be registered with Azure Active Directory. It means that you can grant your Logic Apps to access resources such as Virtual Machines. It is important in our case because the Logic Apps needs to start Virtual Machines.

Azure Active Directory

Navigate to the Virtual Machines blade, select your Virtual Machine, and go to “Access Control (IAM)”. Click “Add” -> “Add role assignment”, then select the “Virtual Machine Contributor” role and link this role to your Logic Apps. You can of course grant this role for all Virtual Machines and not only one VM.

Access Control (IAM)

If your Logic Apps is not running, you can click “Run trigger

Run trigger

Now, you just need to wait until the next schedule of your Logic Apps. The Virtual Machine should be running and you should see in the Activity Log the following output:

Activity Log

In my case, the Virtual Machine has been started and I can confirm that the poweron was initiated by the Logic Apps called “Start-VirtualMachine”

Conclusion

Thanks to the Logic Apps, we can easily perform actions on the Azure resources instead of using Azure Automation. It can be interesting if you do not want to use scripts/runbooks.

Please note that you can of course use Logic Apps to perform actions on resources that are not Virtual Machines. Referring to the following link, you can use API for all the Azure resources: https://docs.microsoft.com/en-us/rest/api/

Hey! Found Nicolas’s insights useful? Looking for a cost-effective, high-performance, and easy-to-use hyperconverged platform?
Taras Shved
Taras Shved StarWind HCI Appliance Product Manager
Look no further! StarWind HCI Appliance (HCA) is a plug-and-play solution that combines compute, storage, networking, and virtualization software into a single easy-to-use hyperconverged platform. It's designed to significantly trim your IT costs and save valuable time. Interested in learning more? Book your StarWind HCA demo now to see it in action!