diff --git a/post-processor/vsphere-template/post-processor.go b/post-processor/vsphere-template/post-processor.go index 2b87f7ffd..2d979930e 100644 --- a/post-processor/vsphere-template/post-processor.go +++ b/post-processor/vsphere-template/post-processor.go @@ -55,6 +55,7 @@ func (p *PostProcessor) Configure(raws ...interface{}) error { "host": &p.config.Host, "username": &p.config.Username, "password": &p.config.Password, + "vm_name": &p.config.VMName, } for key, ptr := range vc { diff --git a/post-processor/vsphere-template/step_create_folder.go b/post-processor/vsphere-template/step_create_folder.go index 8a35672a2..57f1516e6 100644 --- a/post-processor/vsphere-template/step_create_folder.go +++ b/post-processor/vsphere-template/step_create_folder.go @@ -3,8 +3,7 @@ package vsphere_template import ( "context" "fmt" - "path/filepath" - "strings" + "path" "github.com/hashicorp/packer/packer" "github.com/mitchellh/multistep" @@ -24,8 +23,8 @@ func (s *stepCreateFolder) Run(state multistep.StateBag) multistep.StepAction { if s.Folder != "" { ui.Say("Creating or checking destination folders...") - base := filepath.Join(dcPath, "vm") - path := filepath.ToSlash(filepath.Join(base, s.Folder)) + base := path.Join(dcPath, "vm") + fullPath := path.Join(base, s.Folder) si := object.NewSearchIndex(cli.Client) var folders []string @@ -36,23 +35,24 @@ func (s *stepCreateFolder) Run(state multistep.StateBag) multistep.StepAction { // If we don't find it, we save the folder name and continue with the previous path // The iteration ends when we find an existing path otherwise it throws error for { - ref, err = si.FindByInventoryPath(context.Background(), path) + ref, err = si.FindByInventoryPath(context.Background(), fullPath) if err != nil { state.Put("error", err) ui.Error(err.Error()) return multistep.ActionHalt } if ref == nil { - _, folder := filepath.Split(path) - folders = append(folders, folder) - path = path[:strings.LastIndex(path, "/")] + dir, folder := path.Split(fullPath) + fullPath = path.Clean(dir) - if path == dcPath { - err = fmt.Errorf("vSphere base path %s not found", filepath.ToSlash(base)) + if fullPath == dcPath { + err = fmt.Errorf("vSphere base path %s not found", base) state.Put("error", err) ui.Error(err.Error()) return multistep.ActionHalt } + + folders = append(folders, folder) } else { break } diff --git a/post-processor/vsphere-template/step_move_template.go b/post-processor/vsphere-template/step_move_template.go index 9c337f98f..e83616982 100644 --- a/post-processor/vsphere-template/step_move_template.go +++ b/post-processor/vsphere-template/step_move_template.go @@ -2,7 +2,7 @@ package vsphere_template import ( "context" - "path/filepath" + "path" "github.com/hashicorp/packer/packer" "github.com/mitchellh/multistep" @@ -24,7 +24,7 @@ func (s *stepMoveTemplate) Run(state multistep.StateBag) multistep.StepAction { if s.Folder != "" { ui.Say("Moving template...") - folder, err := finder.Folder(context.Background(), filepath.ToSlash(filepath.Join(dcPath, "vm", s.Folder))) + folder, err := finder.Folder(context.Background(), path.Join(dcPath, "vm", s.Folder)) if err != nil { state.Put("error", err) ui.Error(err.Error()) diff --git a/website/source/docs/post-processors/vsphere-template.html.md b/website/source/docs/post-processors/vsphere-template.html.md index 2f81df797..8dae682e5 100644 --- a/website/source/docs/post-processors/vsphere-template.html.md +++ b/website/source/docs/post-processors/vsphere-template.html.md @@ -39,16 +39,11 @@ each category, the available configuration keys are alphabetized. Required: -- `host` (string) - The vSphere host that contains the VM built by the vmware-iso. - -- `insecure` (boolean) - If it's true Skip verification of server certificate. - Default is false +- `host` (string) - The vSphere host that contains the VM built by the vmware-iso. -- `password` (string) - Password to use to authenticate to the - vSphere endpoint. +- `password` (string) - Password to use to authenticate to the vSphere endpoint. -- `username` (string) - The username to use to authenticate to the - vSphere endpoint. +- `username` (string) - The username to use to authenticate to the vSphere endpoint. - `vm_name` (string) - The name of the VM once it is uploaded. @@ -57,3 +52,5 @@ Optional: - `datacenter` (string) - If you have more than one, you will need to specify which one the ESXi used. - `folder` (string) - Target path where the template will be created. + +- `insecure` (boolean) - If it's true skip verification of server certificate. Default is false