Can we automate during the VM provisioning?

We can use Microsoft.DevTestLab/schedules resource to automate this during the provision of VM it self.

VM shutdown options

Manually shutting down a VM to put it in the Stopped (Deallocated) status is a great way to save cost on Azure VM’s. Although, you do need to remember to Stop the VM. This introduces a certain level of human error in the process of saving you hosting costs on your Azure VMs. As a result, Microsoft has added a scheduled auto-shutdown feature into the platform to assist you in this effort. We all know that we can either use run books or use the option of Auto shutdown inside the VM blade. Once it’s configured no you are not worried about running VM, on defined schedule they will be automatically shutdown.

But all this require a manual action to configure.

autoshutdown

As said we can use Microsoft.DevTestLab/schedules resource to automate this during the provision of VM it self. Let’s play

{
    "name": "[concat('shutdown-computevm-', parameters('virtualMachineName'))]",
    "type": "Microsoft.DevTestLab/schedules",
    "apiVersion": "2017-04-26-preview",
    "location": "[parameters('location')]",
    "properties": {
        "status": "[parameters('autoShutdownStatus')]",
        "taskType": "ComputeVmShutdownTask",
        "dailyRecurrence": {
            "time": "[parameters('autoShutdownTime')]"
        },
        "timeZoneId": "[parameters('autoShutdownTimeZone')]",
        "targetResourceId": "[resourceId('Microsoft.Compute/virtualMachines', parameters('virtualMachineName'))]",
        "notificationSettings": {
        "status": "[parameters('autoShutdownNotificationStatus')]",
        "emailRecipient": "[parameters('autoShutdownNotificationEmail')]",
        "notificationLocale": "[parameters('autoShutdownNotificationLocale')]",
        "timeInMinutes": "30"
        }
    },
    "dependsOn": [
       "[concat('Microsoft.Compute/virtualMachines/', parameters('virtualMachineName'))]"
        ]
    },

Please do let me know your thoughts/ suggestions/ question in disqus section.


Related Posts

About Ajeet Chouksey

With a robust background spanning more than 18 years, I am an adept Azure and Azure DevOps architect and engineer, dedicated to crafting Azure-centric solutions that prioritize customer requirements and agile methodologies. My expertise encompasses steering extensive cloud migration initiatives and advocating for Azure best practices, all aimed at streamlining costs and steering multinational teams towards success. Fueled by a passion for technological innovation, I am committed to perpetual learning, constantly advancing my proficiency in Azure, AI, MLOps, and Product Management to stay at the forefront of the industry..