From c387dc2c53220db71d3aa3baa86add7890c442d5 Mon Sep 17 00:00:00 2001 From: Rui Lopes Date: Tue, 24 Mar 2020 15:28:00 +0000 Subject: [PATCH] builder/vsphere-clone: Find the vm within the folder (#8938) --- builder/vsphere/clone/step_clone.go | 9 +++++---- builder/vsphere/iso/step_create.go | 9 +++++---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/builder/vsphere/clone/step_clone.go b/builder/vsphere/clone/step_clone.go index 22c3059c7..ff395738b 100644 --- a/builder/vsphere/clone/step_clone.go +++ b/builder/vsphere/clone/step_clone.go @@ -49,17 +49,18 @@ type StepCloneVM struct { func (s *StepCloneVM) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction { ui := state.Get("ui").(packer.Ui) d := state.Get("driver").(*driver.Driver) + vmPath := fmt.Sprintf("%s/%s", s.Location.Folder, s.Location.VMName) - vm, err := d.FindVM(s.Location.VMName) + vm, err := d.FindVM(vmPath) if s.Force == false && err == nil { - state.Put("error", fmt.Errorf("%s already exists, you can use -force flag to destroy it", s.Location.VMName)) + state.Put("error", fmt.Errorf("%s already exists, you can use -force flag to destroy it", vmPath)) return multistep.ActionHalt } else if s.Force == true && err == nil { - ui.Say(fmt.Sprintf("the vm/template %s already exists, but deleting it due to -force flag", s.Location.VMName)) + ui.Say(fmt.Sprintf("the vm/template %s already exists, but deleting it due to -force flag", vmPath)) err := vm.Destroy() if err != nil { - state.Put("error", fmt.Errorf("error destroying %s: %v", s.Location.VMName, err)) + state.Put("error", fmt.Errorf("error destroying %s: %v", vmPath, err)) } } diff --git a/builder/vsphere/iso/step_create.go b/builder/vsphere/iso/step_create.go index 02bc77f6c..67a59b35e 100644 --- a/builder/vsphere/iso/step_create.go +++ b/builder/vsphere/iso/step_create.go @@ -94,17 +94,18 @@ type StepCreateVM struct { func (s *StepCreateVM) Run(_ context.Context, state multistep.StateBag) multistep.StepAction { ui := state.Get("ui").(packer.Ui) d := state.Get("driver").(*driver.Driver) + vmPath := fmt.Sprintf("%s/%s", s.Location.Folder, s.Location.VMName) - vm, err := d.FindVM(s.Location.VMName) + vm, err := d.FindVM(vmPath) if s.Force == false && err == nil { - state.Put("error", fmt.Errorf("%s already exists, you can use -force flag to destroy it: %v", s.Location.VMName, err)) + state.Put("error", fmt.Errorf("%s already exists, you can use -force flag to destroy it: %v", vmPath, err)) return multistep.ActionHalt } else if s.Force == true && err == nil { - ui.Say(fmt.Sprintf("the vm/template %s already exists, but deleting it due to -force flag", s.Location.VMName)) + ui.Say(fmt.Sprintf("the vm/template %s already exists, but deleting it due to -force flag", vmPath)) err := vm.Destroy() if err != nil { - state.Put("error", fmt.Errorf("error destroying %s: %v", s.Location.VMName, err)) + state.Put("error", fmt.Errorf("error destroying %s: %v", vmPath, err)) } }