Skip to content

Instantly share code, notes, and snippets.

@rohrerb
Created June 20, 2018 12:01
Show Gist options
  • Save rohrerb/724e3d44968d194152175cfa335efe61 to your computer and use it in GitHub Desktop.
Save rohrerb/724e3d44968d194152175cfa335efe61 to your computer and use it in GitHub Desktop.
#! /bin/bash
rg="USTV-Web"
avSetName="myAvSet"
targetsize="Standard_DS2"
avSetDetail=$(az vm availability-set show -g $rg -n $avSetName)
vms=$(echo $avSetDetail | jq '.virtualMachines[]')
avVMIDs=$(echo $vms | jq -r '.id')
#Deallocate the VM before changing the size of the VM
echo "deallocating "$avVMIDs
az vm deallocate --ids $avVMIDs
#Change the VM size to a size that supports premium storage
echo "resizing "$avVMIDs
az vm resize --ids $avVMIDs --size $targetsize
echo $vms | jq -c '.' | while read i; do
id=$(echo $i | jq -r '.id')
storageProfile=$(echo $i | jq '.storageProfile')
#Update the sku of the OS disk
osDisk=$(echo $storageProfile | jq -r '.osDisk.managedDisk.id')
echo "updating osDisk "$osDisk
az disk update --sku Premium_LRS --ids "$osDisk"
echo "terraform state rm azurerm_virtual_machine.vm;"
echo "terraform importazurerm_virtual_machine.vm $id;"
done
az vm start --ids $avVMIDs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment