Is it possible to Deploy Azure Start/Stop VM market place solution programmatically (using Terraform or CLI command)

Jana, Tapas 0 Reputation points
2025-01-09T11:10:00.81+00:00

Dear Azure Community,

I am trying to implement Start/Stop VM automation. Target is to deploy the solution by using terraform to each subscription. I found a market place solution: https://zcusa.951200.xyz/en-us/azure/azure-functions/start-stop-vms/overview?WT.mc_id=Portal-Microsoft_Azure_Marketplace
I am not getting any clue how I can deploy this with an IaC.

Best Regards,
Tapas

Azure Virtual Machines
Azure Virtual Machines
An Azure service that is used to provision Windows and Linux virtual machines.
8,215 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Akshay kumar Mandha 1,880 Reputation points Microsoft Vendor
    2025-01-09T17:25:20+00:00

    Hi Jana, Tapas,
    Thanks for posting you query and using Microsoft Q&A Forum.
    Based on your query, you can go with azure cli with commands to start and stop VM and use azure automation runbooks
    Azure CLI
    Starting a VM

    To get a VM up and running use below command.

    az vm start -g MyResourceGroup -n MyVm
    

    Just replace -g (or --resource-group) with your resource group name and -n (or --name) with the name of your VM.

    If you want to start all VMs in a specific resource group

    az vm start --ids $(az vm list -g MyResourceGroup --query "[].id" -o tsv)
    

    And if you don't want to wait for the operation to finish, you can add the --no-wait parameter to your commands.

    Stopping a VM is very similar to starting one. use below command.

    az vm stop -g MyResourceGroup -n MyVm
    

    And Restarting a VM if you need to restart a VM, you can use this command:

    az vm restart -g MyResourceGroup -n MyVm
    
    
    

    And also, you can use Azure Automation account and create a Runbook. In that Runbook, paste your custom script, and you can schedule it based on your requirements. Please refer to the documentation below on how to set up an Automation account and Runbook.
    Quickstart: Create an Automation account using the Azure portal
    Tutorial: Create a PowerShell Workflow runbook in Automation

    Note: - Before making any changes or setting things up, please make sure backup and all configuration for testing do in testing environment

    Please let us know if you have any further query, I will assist you as needed.!

    If you found this information helpful, please click an accepting the answer and "Upvote" on my post for other community member's reference

    User's image

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.