Virtual Machine Destroy - Operation 'powerOff' is not allowed (409 Conflict)

Hello TF community,

first of all, this is not a bug but a question regarding the current functionality of azurerm_windows_virtual_machine deployment.

Recently, I got an error message during destroy operation of one of my VM:

Error: powering off Windows Virtual Machine (Subscription: “XXXXX”
│ Resource Group Name: “test-resources”
│ Virtual Machine Name: “test-vm”): performing PowerOff: unexpected status 409 (409 Conflict) with error: OperationNotAllowed: Operation ‘powerOff’ is not allowed on VM ‘test-vm’ since the VM is either deallocated or marked to be deallocated. Please refer to States and billing status - Azure Virtual Machines | Microsoft Learn to learn about different VM power states.

At first I thought this is something new with the provider 4.1.0 but since then, I tested this with 3.84.0 and 3.108.0. Always the same error.

The VM is indeed deallocated. What I cannot understand is, why the VM needs to be Powered On for the destroy. This is a new VM deployment. There are no extensions whatsoever. I was looking for some explanation but could not find any (hope not due to my search skills :frowning: ).

Can anyone please explain this behaviour? I would assume the poweroff command returns the status of the VM is deallocated and proceeds with destroying the resource.

Thank you

I’m also seeing this error. Have you seen any changes or progress, or opened a bug on GitHub? I don’t know why this would have changed for us, we’re using the same version of the AzureRM provider we’ve been using for a long time.

I also started to get this error since this Friday (6 Dec 24). I checked GitHub but didn’t see any open bugs yet.

The situation is similar, I am trying to destroy a VM that’s been decallocated because it’s been generalized to create a golden image. And of course by nature, you cannot start / stop generalized VMs anymore.

Honestly I thought this is an expected bahviour. I am going to open an issue on github later for this then. Thank you for confirmation.

I created a GitHub issue, feel free to add more details there @gwynbleide :

1 Like