pythonazureazure-virtual-machineazure-api-managementazure-disk

Unable to attach Data disk to Azure VM


I created a shared disk following Create Disk and when i try to attach it to a VM Update VM i'm getting createOption cannot be changed. Below is the full error,

Disk attachment failed, request response is - {
  "error": {
    "code": "PropertyChangeNotAllowed",
    "message": "Changing property 'dataDisk.createOption' is not allowed.",
    "target": "dataDisk.createOption"
  }

Request Body for Data Disk creation (please note this is a shared disk),

{
  "location": LOCATION,
  "sku": {
    "name": "Premium_LRS"
  },
  "properties": {
    "creationData": {
      "createOption": "empty"
    },
    "osType": "linux",
    "diskSizeGB": SIZE,
    "maxShares": 5,
    "networkAccessPolicy": "AllowAll"
  }
}

Request body for VM Patch request,

{
  "properties": {
    "storageProfile": {
      "dataDisks": [
      {
        "caching" : "ReadOnly",
        "createOption": "Attach",
        "lun": 0,
        "managedDisk" : {
          "id": disk_id,  //-> this disk_id is id of the created disk above
          "storageAccountType": "Premium_LRS"
        }
      }
      ]
    }
  }
}

can someone please point out where im doing wrong. I haven't found much documentation about shared disk attachment, through API.


Solution

  • As I see, there is no problem with your request body that updates the VM. I tried it right now and it works fine. I use the same request body as yours. So you need to check the disk again such as if the lun 0 is already in use.