diff --git a/builder/hyperv/vmcx/builder.go b/builder/hyperv/vmcx/builder.go index e152294be..b72322431 100644 --- a/builder/hyperv/vmcx/builder.go +++ b/builder/hyperv/vmcx/builder.go @@ -221,6 +221,21 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) { errs, fmt.Errorf("CloneFromVMCXPath does not exist: %s", err)) } } + if strings.HasSuffix(strings.ToLower(b.config.CloneFromVMCXPath), ".vmcx") { + // User has provided the vmcx file itself rather than the containing + // folder. + if strings.Contains(b.config.CloneFromVMCXPath, "Virtual Machines") { + keep := strings.Split(b.config.CloneFromVMCXPath, "Virtual Machines") + b.config.CloneFromVMCXPath = keep[0] + } else { + errs = packer.MultiErrorAppend(errs, fmt.Errorf("Unable to "+ + "parse the clone_from_vmcx_path to find the vm directory. "+ + "Please provide the path to the folder containing the "+ + "vmcx file, not the file itself. Example: instead of "+ + "C:\\path\\to\\output-hyperv-iso\\Virtual Machines\\filename.vmcx"+ + ", provide C:\\path\\to\\output-hyperv-iso\\.")) + } + } } if b.config.Generation < 1 || b.config.Generation > 2 { diff --git a/website/source/docs/builders/hyperv-vmcx.html.md.erb b/website/source/docs/builders/hyperv-vmcx.html.md.erb index 493a78109..f0ec9de2a 100644 --- a/website/source/docs/builders/hyperv-vmcx.html.md.erb +++ b/website/source/docs/builders/hyperv-vmcx.html.md.erb @@ -33,7 +33,7 @@ Import from folder: ``` json { "type": "hyperv-vmcx", - "clone_from_vmcx_path": "c:/virtual machines/ubuntu-12.04.5-server-amd64", + "clone_from_vmcx_path": "c:/path/to/ubuntu-12.04.5-server-amd64", "ssh_username": "packer", "ssh_password": "packer", "shutdown_command": "echo 'packer' | sudo -S shutdown -P now" @@ -77,6 +77,10 @@ builder. previously exported virtual machine. The exported machine will be used as the source for new VM. + note: You should provide the named directory that contains the + "Virtual Machines", "Snapshots", and/or "Virtual Hard Disks" subdirectories, + not the .vmcx file itself. + ### Required for virtual machine clone: