azure icon indicating copy to clipboard operation
azure copied to clipboard

Attaching existing managed disk(s) at VM creation

Open wrprice opened this issue 5 years ago • 7 comments

The use case is that I have an existing managed disk that is not attached to any VM. I want to now create a VM that uses this disk, and the disk must be attached at provisioning time so that it is accessible/visible to initial provisioning scripts (i.e. cloud-init).

Specifically, creating the VM and associating the disk with it later is not sufficient. That is why using the azure_rm_manageddisk module to control the disk's managed_by property is not a viable workaround.

There is an example in the documentation, see lun: 0:

- name: Create a VM with OS and multiple data managed disks
  azure_rm_virtualmachine:
    # ...
    data_disks:
      - lun: 0
        managed_disk_id: "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxxxxxx/resourceGroups/myResourceGroup/providers/Microsoft.Compute/disks/myDisk"
      - lun: 1
        disk_size_gb: 128
        managed_disk_type: Premium_LRS

This appears to be a missing feature. The managed_disk_id property is not defined in the documentation, and the only use in the module source code appears to be for deleting VMs and their resources. On create, the following error is observed:

azure_rm_virtualmachine.py, line 1414, in exec_module KeyError: 'disk_size_gb'

Currently, all data disks needed during initial provisioning must be created new, by this module, as in the example above for lun: 1 and cannot use an existing disk. It also means the user cannot have fine-grained control of the disk's name or other properties in advance. Using other modules to attach a data disk after the VM has been provisioned is possible, as long as the disk is not needed during initial provisioning.

Reopened from Azure/azure_preview_modules/issues/362 which was closed due to repo/project migration.

wrprice avatar Jun 04 '20 14:06 wrprice

@wrprice Thank you very much for submitting this issue, I am looking for the cause and fixing it! Thank you!

Fred-sun avatar Jul 30 '20 09:07 Fred-sun

Has there been any progress on this?

I have a scenario where I need to attach an existing managed disk as part of the deployment pipeline

andyliddle avatar Feb 09 '21 15:02 andyliddle

@andyliddle Working on it! Thank you very much

Fred-sun avatar Feb 18 '21 00:02 Fred-sun

Any update on this?

tolarewaju3 avatar Apr 14 '21 19:04 tolarewaju3

Also with this error. Any updates ?

carlosrbcunha avatar Aug 19 '21 15:08 carlosrbcunha

Hitting this issue as well, managed_disk_id does not seem supported by azure_rm_virtualmachine. Thanks!

nbr23 avatar Aug 26 '21 05:08 nbr23

I have made a PR with this feature: https://github.com/ansible-collections/azure/pull/1430

galibozek avatar Feb 02 '24 16:02 galibozek