I’m working on an automation project involving creating and modifying Azure VMs using Terraform version 0.12.24 and azurerm 2.12.0.
Performing some modification on existing VMs I’ve noticed a bit of a strange behavior for their powerstate. Specifically:
Modifying VMs’ SKU the initial power state is preserved at the end of the operation, meaning that if it was Running after the modify which always stop the VM it’s brought back to Running, if was Stopped will remain Stopped;
Modifying the size of an attached managed disk the VM will be always started at the end of the process disregarding it’s previous state (Running or Stopped).
I dig a little bit into the code and I saw that actually the two processes use different approach and piece of code:
for a modification of SKU the need to restart a VM is evaluated by the function func virtualMachineShouldBeStarted, defined in virtual_machine_instance.go that return true only if the VM is already running and this work for both windows_virtual_machine_resource and linux_virtual_machine_resource
for a managed disk modification in the function resourceArmManagedDiskUpdate defined in managed_disk_resource.go there is a switch case that set the variable shouldTurnBackOn to false if the machine is deallocating or stopped and otherwise leave the variable shouldTurnBackOn which is a little bit confusing to me.
Is there any rationale behind this kind of implementation and different behavior that I do not see?
I also think it could be useful to have some kind of control over the power state of a VM, like the desired_status for google_compute_instance in the google provider, am I missing something here or this feature is not yet possible in azurerm?
Thank you and excuse me for this very long first post