Terraform-provider-azurerm: azurerm_linux_virtual_machine does not support data disks which is blocking for cloud-init configuration

Created on 11 Mar 2020  路  12Comments  路  Source: terraform-providers/terraform-provider-azurerm

Community Note

  • Please vote on this issue by adding a 馃憤 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Terraform (and AzureRM Provider) Version

Affected Resource(s)

  • azurerm_linux_virtual_machine

Important Factoids

The azurerm_virtual_machineresource supports data_disks, but this isn't possible with the new azurerm_linux_virtual_machine or azurerm_windows_virtual_machine.

[edit]

As soon as the vm is created, the cloud-init initialization starts. As we can not attach a data disk in a single operation with azurerm_linux_virtual_machine, we can not mount nor do anything with the data disk during the cloud-init operation.

However, it's pretty common (a best practice) to

  • use cloud-init for vm initialization
  • rely on a data disk for persistent data

馃憠 This use case is not possible anymore. 馃槩

question servicvirtual-machine

Most helpful comment

Thanks @ArcturusZhang for your answer.

But having a separate resource for that does not enable my use case, where the custom data script (a cloud-init script) mount the data disk volume and do stuff on it.

All 12 comments

Hi @boillodmanuel thanks for this issue, but in 2.0 the azurerm_linux_virtual_machine (as well as azurerm_windows_virtual_machine) must use the new resource azurerm_virtual_machine_data_disk_attachment to attach data disk for them.
Here is the doc page for azurerm_virtual_machine_data_disk_attachment: https://www.terraform.io/docs/providers/azurerm/r/virtual_machine_data_disk_attachment.html

Thanks @ArcturusZhang for your answer.

But having a separate resource for that does not enable my use case, where the custom data script (a cloud-init script) mount the data disk volume and do stuff on it.

To fulfil my answer, I'm able to do that with current "azurerm_virtual_machine".

Hello @ArcturusZhang , any update about this use case ? The #6117 is a similar issue.

You may be able to use azurerm_virtual_machine_extension to run your customization.
You need to add depends_on in azurerm_virtual_machine_extension that point to the id of azurerm_virtual_machine_data_disk_attachment

That should achieve the same goal.

Hello @jpbuecken, I could do that, but this is an ugly workaround, and force me to rewrite everything in a non-standard way.

Indeed, the standard way of initializing a VM is using cloud-init. It's now mainstream for at least Azure, AWS, GCP.

If I use azurerm_virtual_machine_extension, I cannot rely to cloud-init mechanism anymore.
It's a breaking change from azurerm_virtual_machine 馃槺.

For my company, this prevents us to move to the new azurerm_linux_virtual_machine resource, and we are forced to stay on the deprecated azurerm_virtual_machine resource 馃槦.

Hello, any news about this issue? How are you considering it?
Do you need more details?

I updated the main issue with comments content to get a clear overview

Just discovered a related issue for the windows version: #6004

I'm facing the same issue, if I use a image with data disk and try to create with azurerm_linux_virtual_machine occurs the 400 error.

Reporting error relating to this issue

Message="StorageProfile.dataDisks.lun does not have required value(s) for image specified in storage profile." Target="storageProfile"

Similar to the error you see for the windows virtual machine resource #6004

Hello! This bug is still present and is making us use "azurerm_virtual_machine" for deploy VMs that are custom created by vendor, like:

publisher = "IBM"
offer     = "qradar733"
sku       = "mh733"
version   = "latest"
Was this page helpful?
0 / 5 - 0 ratings