Forum Discussion
ARM Template: Prevent VM from starting after deployment
Hi all,
I just created a new Azure ARM template to deploy virtual machines. I've configured a scheduled shutdown task in it to make sure it shuts down at the end of the day.
After deploying the ARM template the virtual machine is started immediately. I want to prevent this in my ARM template if that's possible. I don't see anything in the API documentation about this: https://docs.microsoft.com/en-us/azure/templates/microsoft.compute/2020-06-01/virtualmachines
Anyone a creative idea to prevent a VM from booting after deployment?
2 Replies
- ibnmbodjiIron Contributor
Hi
I don't think it's possible you can identify the resource group in wich VM to stop will be deployed and create a runbook that would have the code below so each Vm you deployed will be stopped :
Param(
[string]$VmName,
[string]$ResourceGroupName,
[ValidateSet("Startup", "Shutdown")]
[string]$VmAction
)
# Login to Automation Account
$Conn = Get-AutomationConnection -Name AzureRunAsConnection
Add-AzureRMAccount -ServicePrincipal -Tenant $Conn.TenantID `
-ApplicationID $Conn.ApplicationID -CertificateThumbprint $Conn.CertificateThumbprint | Out-Null
# Shutdown Virtual Machines
$vms = $VmName.split(',')
foreach($vm in $vms) {
IF ($VmAction -eq "Shutdown") {
Stop-AzureRmVM -Name $Vm -ResourceGroupName $ResourceGroupName -Force | Out-Null
#Write-Output "VM $Vm in Resource Group $ResourceGroupName was stopped Successfully"
$objOut = [PSCustomObject]@{
ResourceGroupName = $ResourceGroupName
VMName = $Vm
VMAction = $VmAction
}
Write-Output ( $objOut | ConvertTo-Json)
}- jvldnCopper ContributorLooks like an option! I’ll check tomorrow but in our case we have more vm’s in the same resource group. I’ll check if i can figure this out 🙂
Thanks!