hashicorp / terraform-provider-azurerm

Terraform provider for Azure Resource Manager
https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs
Mozilla Public License 2.0
4.6k stars 4.64k forks source link

Support data disk attachments for Virtual Machine Scale Sets #17702

Open BuriedStPatrick opened 2 years ago

BuriedStPatrick commented 2 years ago

Is there an existing issue for this?

Community Note

Description

Currently it's possible to add a managed disk attachment to individual VMs using azurerm_virtual_machine_data_disk_attachment. But there doesn't seem to be any support for this when it comes to Virtual Machine Scalesets.

This is already possible in Azure.

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

Potential Terraform Configuration

I have two suggestions on the configuration with some variation.

Suggestion 1: As part of the VMSS definition

Variation A

Add an attached_data_disk property mirroring data_disk. Difference being it would be shared between all VM instances.

resource "azurerm_linux_virtual_machine_scale_set" "example" {
  ...
  attached_data_disk {
    ...
    # Same properties as `data_disk` would have
    storage_account_type = "Standard_LRS"
    create_option        = "Empty"
    disk_size_gb         = 64
  }
}
Variation B

Instead of a new property attached_data_disk, simply switch on a new property data_disk.type.

resource "azurerm_linux_virtual_machine_scale_set" "example" {
  ...
  data_disk {
    ...
    storage_account_type = "Standard_LRS"
    create_option        = "Empty"
    disk_size_gb         = 64
    type                 = "attached" # Defaults to 'local' or something similar sounding
  }
}

Suggestion 2: As a separate attachment resource

This is similar to how it's done for azurerm_virtual_machine with azurerm_virtual_machine_disk_attachment.

resource "azurerm_linux_virtual_machine_scale_set" "example" {
  ...
}

resource "azurerm_managed_disk" "example" {
  ...
  storage_account_type = "Standard_LRS"
  create_option        = "Empty"
  disk_size_gb         = 64
}

resource "azurerm_virtual_machine_scaleset_disk_attachment" "example" {
  ...
  managed_disk_id             = azurerm_managed_disk.example.id
  virtual_machine_scaleset_id = azurerm_linux_virtual_machine_scale_set.example.id
  lun                         = 0
}

References

BuriedStPatrick commented 2 years ago

This was not supposed to be posted until I was absolutely sure and had a potential configuration. I can't delete it, so I will update with potential config later.

Enter-button got me in the New or Affected Resource(s)/Data Source(s) field and submitted instead of adding a line, sorry.

Edit: I updated the issue with some configuration examples. I also have not been able to find any other issues regarding this problem apart from someone else having a similar issue not getting any help on the Terraform forums.

kubernitos commented 2 years ago

Any update on this?

acarrere184 commented 1 year ago

Any update?

rongallagher commented 1 year ago

Has there been any progress on implementing this enhancement?

samcarswell commented 8 months ago

This looks like it was added in https://github.com/hashicorp/terraform-provider-azurerm/releases/tag/v3.21.0

dgonzalezp commented 7 months ago

@samcarswell if you're saying about the block data_disk , it allows you to create a new drive, but not to attach an existing one. Looking forward this update

gh-tek commented 3 months ago

I was about to create a cluster with shared disk and hit my head with this. data_disk only seems to be capable of creating local disk, while in Azure it is also possible to attach separate disk as shared to all nodes.

But I guess this also requires change to azurerm_managed_disk since there needs to MaxShares setting: https://learn.microsoft.com/en-us/azure/virtual-machines/disks-shared-enable?tabs=azure-resource-manager