From 6e5da78f7928ef95c133565e587f01312fe4b765 Mon Sep 17 00:00:00 2001 From: dkalleg Date: Thu, 28 Apr 2016 16:44:30 -0700 Subject: [PATCH] Fixing hard disk path when specifying only size (#6400) We were passing in a disk path of `[datastore] `, which the createDisk call would create a file named `.vmdk` on the datastore, which is not the expected behavior. This make sure that if the user did not pass in a vmdk path, that we call CreateDisk with an empty string like it expects. --- .../vsphere/resource_vsphere_virtual_machine.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/builtin/providers/vsphere/resource_vsphere_virtual_machine.go b/builtin/providers/vsphere/resource_vsphere_virtual_machine.go index 5984f29ff..e2fc3cb6f 100644 --- a/builtin/providers/vsphere/resource_vsphere_virtual_machine.go +++ b/builtin/providers/vsphere/resource_vsphere_virtual_machine.go @@ -811,8 +811,15 @@ func addHardDisk(vm *object.VirtualMachine, size, iops int64, diskType string, d } log.Printf("[DEBUG] disk controller: %#v\n", controller) - // TODO Check if diskPath & datastore exist - disk := devices.CreateDisk(controller, fmt.Sprintf("[%v] %v", datastore.Name(), diskPath)) + // If diskPath is not specified, pass empty string to CreateDisk() + var newDiskPath string + if diskPath == "" { + newDiskPath = "" + } else { + // TODO Check if diskPath & datastore exist + newDiskPath = fmt.Sprintf("[%v] %v", datastore.Name(), diskPath) + } + disk := devices.CreateDisk(controller, newDiskPath) existing := devices.SelectByBackingInfo(disk.Backing) log.Printf("[DEBUG] disk: %#v\n", disk)