Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for storage_data_disk in azurerm_linux_virtual_machine #17373

Closed
1 task done
djryanj opened this issue Jun 24, 2022 · 2 comments
Closed
1 task done

Support for storage_data_disk in azurerm_linux_virtual_machine #17373

djryanj opened this issue Jun 24, 2022 · 2 comments

Comments

@djryanj
Copy link
Contributor

djryanj commented Jun 24, 2022

Is there an existing issue for this?

  • I have searched the existing issues

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

Description

Currently, storage_data_disk is not an attribute that azurerm_linux_virtual_machine or azurerm_windows_virtual_machine supports and we are forced to use a secondary azurerm_managed_disk and azurerm_virtual_machine_data_disk_attachment. While on the surface, this doesn't seem like a big deal, in some cases this can cause problems.

Issues with not being able to use a storage_data_disk in an azurerm_linux_virtual_machine specifically:

  • If using a cloud-init/user_data/custom_data script that mounts a disk to a specific location, it's very likely that the disk won't actually be created or attached when the script runs in the VM. Therefore the script fails.
  • In line with above, if we are creating a VM from a custom image that requires either a snapshotted data disk to exist to be mounted at a specific location, that's not possible either at the moment (or it will cause a bunch of errors in the VM when it boots up, presuming the disk mounts to the right spot in the end).

As it stands, if we want to leverage that kind of functionality, we have to revert to using the (soon to be deprecated) azurerm_virtual_machine resource.

New or Affected Resource(s)/Data Source(s)

azurerm_linux_virtual_machine, azurerm_windows_virtual_machine

Potential Terraform Configuration

resource "azurerm_resource_group" "example" {
  name     = "example-resources"
  location = "West Europe"
}

resource "azurerm_virtual_network" "example" {
  name                = "example-network"
  address_space       = ["10.0.0.0/16"]
  location            = azurerm_resource_group.example.location
  resource_group_name = azurerm_resource_group.example.name
}

resource "azurerm_subnet" "example" {
  name                 = "internal"
  resource_group_name  = azurerm_resource_group.example.name
  virtual_network_name = azurerm_virtual_network.example.name
  address_prefixes     = ["10.0.2.0/24"]
}

resource "azurerm_network_interface" "example" {
  name                = "example-nic"
  location            = azurerm_resource_group.example.location
  resource_group_name = azurerm_resource_group.example.name

  ip_configuration {
    name                          = "internal"
    subnet_id                     = azurerm_subnet.example.id
    private_ip_address_allocation = "Dynamic"
  }
}

resource "azurerm_linux_virtual_machine" "example" {
  name                = "example-machine"
  resource_group_name = azurerm_resource_group.example.name
  location            = azurerm_resource_group.example.location
  size                = "Standard_F2"
  admin_username      = "adminuser"
  network_interface_ids = [
    azurerm_network_interface.example.id,
  ]

  admin_ssh_key {
    username   = "adminuser"
    public_key = file("~/.ssh/id_rsa.pub")
  }

  os_disk {
    caching              = "ReadWrite"
    storage_account_type = "Standard_LRS"
  }

  source_image_reference {
    publisher = "Canonical"
    offer     = "UbuntuServer"
    sku       = "16.04-LTS"
    version   = "latest"
  }

  storage_data_disk {
    name          = "datadisk-1"
    lun           = 1
    create_option = "Empty"
  }
}

References

https://stackoverflow.com/questions/61085490/using-cloud-init-on-an-azure-vm-to-mount-a-data-disk-fails

@tombuildsstuff
Copy link
Contributor

hi @djryanj

Thanks for opening this issue.

Taking a look through this appears to be a duplicate of #6117 - rather than having multiple issues open tracking the same thing I'm going to close this issue in favour of that one; would you mind subscribing to #6117 for updates?

Thanks!

@github-actions
Copy link

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 25, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants