1
votes

Using a Logic App, calling the Azure Rest API from an HTTP request action, I am trying to create a managed disk (from snapshot) and then ATTACH the disk to an existing VM. I can get the disk from snapshot created - this is easy enough. However, I can't get the Rest API call correct which tries to attach a disk.

I have a PUT request like this: https://management.azure.com/subscriptions/xxxxx-xxxx-cxxxxxfxxxx-xxxxxx/resourceGroups/rgname/providers/Microsoft.Compute/virtualMachines/vm-test?api-version=2020-06-30

and a JSON body like: { "dataDisks": { "caching": "None", "createOption": "Attach", "lun": 6, "managedDisk": { "id": "/subscriptions/xxxxx-xxxx-cxxxxxfxxxx-xxxxxx/resourceGroups/rgname/providers/Microsoft.Compute/disks/disk-12345-november", "storageAccountType": "Standard_LRS" } } }

This is valid JSON. The error from Azure is "bad reqeust"

{ "error": { "code": "ResourceReadFailed", "target": "vm-test", "message": "Policy required full resource content to evaluate the request. The request to GET resource 'https://management.azure.com/subscriptions/xxxxxxx-xxxxxxxx-xxxxxxxx-xxxxxxx/resourceGroups/rg-name/providers/Microsoft.Compute/virtualMachines/vm-test?api-version=2020-06-30' failed with status 'BadRequest'." } }

1

1 Answers

2
votes

The REST API you used is the right one, but you need to use a more complete body like below:

{
  "properties": {
      "storageProfile": {
        "dataDisks": [
            {
                "createOption": "Attach",
                "lun": 1,
                "managedDisk": {
                    "id": "xxxxx"
                }
            }
        ]
    }
  }
}