Troubleshoot virtual machine deployment due to detached disks
Article
Applies to: ✔️ Windows VMs
Symptom
When you're trying to update a virtual machine whose previous data disk detach failed, you might come across this error code.
Code=\"AttachDiskWhileBeingDetached\"
Message=\"Cannot attach data disk '{disk ID}' to virtual machine '{vmName}' because the disk is currently being detached or the last detach operation failed. Please wait until the disk is completely detached, and then try again or delete/detach the disk explicitly again\”
Cause
This error happens when you try reattaching a data disk whose last detach operation failed. The best way to get out of this state is to detach the failing disk.
Get the array index of the failing disk and set the toBeDetached flag for the failing disk (for which AttachDiskWhileBeingDetached error occurred) to "true". This setting implies detaching the disk from the virtual machine. The failing disk name can be found in the errorMessage.
Note
The API version specified for Get and Put calls needs to be 2019-03-01 or greater.
GET https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{vmName}?$expand=instanceView&api-version=2019-03-01
Step 2: Set the flag for failing disks to "true"
Set the toBeDetached flag for failing disk to true in the payload returned in Step 1. Please Note: The API version specified for Get and Put calls needs to be 2019-03-01 or greater.
Learn about your virtual machine storage options and how to choose between standard and premium, managed and unmanaged disks for your Azure virtual machine.