VMWare virtual disk label drift between terraform & vSphere

Hi everyone!

When managing disks using the vmware vsphere terraform provider, a label is required.
it seems the label you provide to the vmware vsphere provider can drift from the label used by VMWare.

For example:

Terraform:

resource "vsphere_virtual_machine" "vm" {
...
    
    dynamic "disk" {
        for_each = each.value.disks
        content {
            label = disk.value.label
            size  = disk.value.size_gb
            unit_number = disk.value.controller_location
        }
    }

If a VM has 3 disks labeled:

  • Hard disk 1
  • Hard disk 2
  • Hard disk 3

And I remove Hard disk 2 through Terraform, the Terraform state will remember:

  • Hard disk 1
  • Hard disk 3

But the vSphere API & UI seem to shuffle the disks to:

  • Hard disk 1
  • Hard disk 2

Renaming labels in Terraform to match the actual labels used by VMware triggers the disks to be deleted and recreated.

Am I missing something? Is there a way to work around this?

Any feedback or suggestions would be greatly appreciated!