Skip to content

Commit c387dc2

Browse files
authored
builder/vsphere-clone: Find the vm within the folder (#8938)
1 parent b17b211 commit c387dc2

2 files changed

Lines changed: 10 additions & 8 deletions

File tree

builder/vsphere/clone/step_clone.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,18 @@ type StepCloneVM struct {
4949
func (s *StepCloneVM) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
5050
ui := state.Get("ui").(packer.Ui)
5151
d := state.Get("driver").(*driver.Driver)
52+
vmPath := fmt.Sprintf("%s/%s", s.Location.Folder, s.Location.VMName)
5253

53-
vm, err := d.FindVM(s.Location.VMName)
54+
vm, err := d.FindVM(vmPath)
5455

5556
if s.Force == false && err == nil {
56-
state.Put("error", fmt.Errorf("%s already exists, you can use -force flag to destroy it", s.Location.VMName))
57+
state.Put("error", fmt.Errorf("%s already exists, you can use -force flag to destroy it", vmPath))
5758
return multistep.ActionHalt
5859
} else if s.Force == true && err == nil {
59-
ui.Say(fmt.Sprintf("the vm/template %s already exists, but deleting it due to -force flag", s.Location.VMName))
60+
ui.Say(fmt.Sprintf("the vm/template %s already exists, but deleting it due to -force flag", vmPath))
6061
err := vm.Destroy()
6162
if err != nil {
62-
state.Put("error", fmt.Errorf("error destroying %s: %v", s.Location.VMName, err))
63+
state.Put("error", fmt.Errorf("error destroying %s: %v", vmPath, err))
6364
}
6465
}
6566

builder/vsphere/iso/step_create.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,17 +94,18 @@ type StepCreateVM struct {
9494
func (s *StepCreateVM) Run(_ context.Context, state multistep.StateBag) multistep.StepAction {
9595
ui := state.Get("ui").(packer.Ui)
9696
d := state.Get("driver").(*driver.Driver)
97+
vmPath := fmt.Sprintf("%s/%s", s.Location.Folder, s.Location.VMName)
9798

98-
vm, err := d.FindVM(s.Location.VMName)
99+
vm, err := d.FindVM(vmPath)
99100

100101
if s.Force == false && err == nil {
101-
state.Put("error", fmt.Errorf("%s already exists, you can use -force flag to destroy it: %v", s.Location.VMName, err))
102+
state.Put("error", fmt.Errorf("%s already exists, you can use -force flag to destroy it: %v", vmPath, err))
102103
return multistep.ActionHalt
103104
} else if s.Force == true && err == nil {
104-
ui.Say(fmt.Sprintf("the vm/template %s already exists, but deleting it due to -force flag", s.Location.VMName))
105+
ui.Say(fmt.Sprintf("the vm/template %s already exists, but deleting it due to -force flag", vmPath))
105106
err := vm.Destroy()
106107
if err != nil {
107-
state.Put("error", fmt.Errorf("error destroying %s: %v", s.Location.VMName, err))
108+
state.Put("error", fmt.Errorf("error destroying %s: %v", vmPath, err))
108109
}
109110
}
110111

0 commit comments

Comments
 (0)