azure
azure copied to clipboard
Attaching existing managed disk(s) at VM creation
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 Thank you very much for submitting this issue, I am looking for the cause and fixing it! Thank you!
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 Working on it! Thank you very much
Any update on this?
Also with this error. Any updates ?
Hitting this issue as well, managed_disk_id does not seem supported by azure_rm_virtualmachine. Thanks!
I have made a PR with this feature: https://github.com/ansible-collections/azure/pull/1430