Specifying location for vms on datastore

I was wondering as I couldn’t find it in the documentation or I’ve missed it a lot.

I am using Terraform 0.12.9 with newest vsphere provider. My goal is to do a clone from a template and it basically works without any problem.

Requirement I am missing is to specify a folder(a local path on datastore) where vm is stored. By default it goes to /, however I would need to have it for example under /vms_xx/.

I’ve seen that you could create pre-existing disk and attach it, however it doesn’t work with clone option.

Is it the case that you simply can’t do it or am I missing something something? If it’s #1, any workarounds you can suggest?

Try to use the disk block in the vsphere_virtual_machine resource.

Here is an example using a dynamic block.

  dynamic "disk" {
    for_each = {
      C = {
        label        = "disk0"
        size         = var.disk_size_C
        datastore_id = data.vsphere_datastore.C_Volumes.id
        unit_number  = 0
      D = {
        label        = "disk1"
        size         = var.disk_size_D
        datastore_id = data.vsphere_datastore.D_Volumes.id
        unit_number  = 1

    content {
      label        = disk.value.label
      size         = disk.value.size
      datastore_id = disk.value.datastore_id
      unit_number  = disk.value.unit_number

Note, the number of disk block must match the number of disks in the cloned vm.