diff --git a/builder/vsphere/common/step_config_params.go b/builder/vsphere/common/step_config_params.go index d13096109..140326b24 100644 --- a/builder/vsphere/common/step_config_params.go +++ b/builder/vsphere/common/step_config_params.go @@ -51,9 +51,7 @@ func (s *StepConfigParams) Run(_ context.Context, state multistep.StateBag) mult if s.Config.ToolsUpgradePolicy { info.ToolsUpgradePolicy = "UpgradeAtPowerCycle" } - } - if len(configParams) > 0 || info != nil { ui.Say("Adding configuration parameters...") if err := vm.AddConfigParams(configParams, info); err != nil { state.Put("error", fmt.Errorf("error adding configuration parameters: %v", err)) diff --git a/builder/vsphere/driver/vm.go b/builder/vsphere/driver/vm.go index 423addab0..a282e7b99 100644 --- a/builder/vsphere/driver/vm.go +++ b/builder/vsphere/driver/vm.go @@ -802,29 +802,29 @@ func (vm *VirtualMachine) addDevice(device types.BaseVirtualDevice) error { func (vm *VirtualMachine) AddConfigParams(params map[string]string, info *types.ToolsConfigInfo) error { var confSpec types.VirtualMachineConfigSpec + var err error - if len(params) > 0 { - var ov []types.BaseOptionValue - for k, v := range params { - o := types.OptionValue{ - Key: k, - Value: v, - } - ov = append(ov, &o) + var ov []types.BaseOptionValue + for k, v := range params { + o := types.OptionValue{ + Key: k, + Value: v, } - confSpec.ExtraConfig = ov + ov = append(ov, &o) + } + confSpec.ExtraConfig = ov + + confSpec.Tools = info + + if len(confSpec.ExtraConfig) > 0 || confSpec.Tools != nil { + task, err := vm.vm.Reconfigure(vm.driver.ctx, confSpec) + if err != nil { + return err + } + + _, err = task.WaitForResult(vm.driver.ctx, nil) } - if info != nil { - confSpec.Tools = info - } - - task, err := vm.vm.Reconfigure(vm.driver.ctx, confSpec) - if err != nil { - return err - } - - _, err = task.WaitForResult(vm.driver.ctx, nil) return err }