hashicorp / terraform-provider-vsphere

Terraform Provider for VMware vSphere
https://registry.terraform.io/providers/hashicorp/vsphere/
Mozilla Public License 2.0
614 stars 448 forks source link

Cannot increased attached disk size #2275

Open thesefer opened 4 days ago

thesefer commented 4 days ago

Community Guidelines

Terraform

Terraform v1.4.2

Terraform Provider

v2.8.3

VMware vSphere

8.0.3.00200

Description

It is not possible to extend an attached virtual disk (on a running vm) after v2.8.3 with the Fix provided by #851

Affected Resources or Data Sources

Terraform Configuration

resource "vsphere_virtual_disk" "PersistentDataDisk" {
  count                   = var.persistent_data_disk == true ? length(var.vms) : 0
  size                  = var.vms[count.index].flavor.disks[1].size
  datacenter            = var.datacenter
  vmdk_path             = "${var.vms[count.index].general.vm_name} - PersistentDisk/${var.vms[count.index].general.host_name}_persistent.vmdk"
  datastore             = var.vms[count.index].general.datastore
  type                  = "thin"
  create_directories    = true
}

resource "vsphere_virtual_machine" "vms" {
  depends_on       = [data.vsphere_virtual_machine.template, vsphere_virtual_disk.PersistentDataDisk]
  count              = length(var.vms)
  host_system_id   = data.vsphere_host.esxi_hosts[count.index].id
  name             = var.vms[count.index].general.vm_name
  resource_pool_id = data.vsphere_compute_cluster.compute_cluster[count.index].resource_pool_id
  datastore_id     = data.vsphere_datastore.datastores[count.index].id
  annotation         = var.vms[count.index].custom_attr.annotation
  firmware         = var.firmware
  folder           = var.vms[count.index].location.folder_name
  enable_disk_uuid =  true

  custom_attributes = tomap({
    (data.vsphere_custom_attribute.admin_contact.id) = (var.vms[count.index].custom_attr.admin_contact)
    (data.vsphere_custom_attribute.owner_name.id) = (var.vms[count.index].custom_attr.owner_name)
  })

  num_cpus = var.vms[count.index].flavor.cpu
  memory   = var.vms[count.index].flavor.ram
  guest_id = var.vms[count.index].general.guest_id

  dynamic "network_interface" {
    for_each = data.vsphere_network.networks
    content {
      network_id = network_interface.value.id
    }
  }

  dynamic disk {
    for_each = [for i in var.vms[count.index].flavor.disks: { 
      size   = i.size
      number = i.number
      attach = var.persistent_data_disk == true ? true : false
      path   = "${var.vms[count.index].general.vm_name} - PersistentDisk/${var.vms[count.index].general.host_name}_persistent.vmdk"
    }]
    content {
      label = "disk${disk.value.number}"
      unit_number = disk.value.number
      size = (disk.value.attach == true && disk.value.number != 1) || disk.value.attach == false ? disk.value.size : null
      thin_provisioned = (disk.value.attach == true && disk.value.number != 1) || disk.value.attach == false ? true : null
      attach = disk.value.attach == true && disk.value.number == 1 ? disk.value.attach : null
      path = disk.value.attach == true && disk.value.number == 1 ? disk.value.path : null
      datastore_id = disk.value.attach == true && disk.value.number == 1 ? data.vsphere_datastore.datastores[count.index].id : null
    }
  }

  clone {
    template_uuid = data.vsphere_virtual_machine.template[count.index].id

    customize {
      linux_options {
        host_name = var.vms[count.index].general.host_name
        domain = var.vms[count.index].general.domain
      }

      dynamic "network_interface" {
        for_each = [for i in var.vms[count.index].network_interfaces: {
          ipv4_address = i.ipv4_address
          ipv4_netmask = i.ipv4_netmask
        }]
        content {
          ipv4_address = network_interface.value.ipv4_address
          ipv4_netmask = network_interface.value.ipv4_netmask
        }
      }

      dns_server_list = var.global_dns_server_list
      ipv4_gateway = var.global_ipv4_gateway
    }
  }
}

Debug Output

https://gist.github.com/thesefer/4e4aa9028faaeba7cb6feeee617a6b6c

Panic Output

No response

Expected Behavior

I expect the disk to be increased. What I can see in vSphere is a Extend virtual disk operation and I would have expected a Reconfigure virtual machine operation because a disk increase works perfectly fine doing it manually in the webinterface.

vSphere

 Reconfigure virtual machine
 TLP89 - Testinstance - Ansible
 Completed
Reconfiguring Virtual Machine on destination host

Actual Behavior

vSphere

Extend virtual disk
 Unable to access file [S-LP11] TLP89 - Testinstance - Ansible - PersistentDisk/tlp89_persistent.vmdk since it is locked

Terraform

โ”‚ Error: Unable to access file [S-LP11] TLP89 - Testinstance - Ansible - PersistentDisk/tlp89_persistent.vmdk since it is locked
โ”‚ 
โ”‚   with vsphere_virtual_disk.PersistentDataDisk[0],
โ”‚   on resources.tf line 48, in resource "vsphere_virtual_disk" "PersistentDataDisk":
โ”‚   48: resource "vsphere_virtual_disk" "PersistentDataDisk" {

Steps to Reproduce

Environment Details

No response

Screenshots

No response

References

851

github-actions[bot] commented 4 days ago

Hello, thesefer! ๐Ÿ–

Thank you for submitting an issue for this provider. The issue will now enter into the issue lifecycle.

If you want to contribute to this project, please review the contributing guidelines and information on submitting pull requests.

tenthirtyam commented 1 day ago

Assigning to @spacegospod since this was noted as resolved in v2.8.3 with https://github.com/hashicorp/terraform-provider-vsphere/pull/2244.