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

As Technology Architect, Ajeet has over 12+ years of industry experience delivering enterprise solutions on the Microsoft Platform. Ajeet is passionate, certified technologist, blogger and community contributor. His specialisms are Azure IaaS/PaaS, Automation, DevOps, Agile based development processes supporting distributed teams (on shore & off shore), designing and implementing the appropriate infrastructure and platform solutions to meet the functional, operational, and deployment requirements throughout the solution life-cycle. Ajeet is member of various technical communities and discussion groups. He also conducted many boot camps on Azure and DevOps.