Skip to content

Commit bfdf005

Browse files
committed
fix: always apply hardware configuration
Updated `StepConfigureHardware` to always run hardware configuration, even when the config is empty, to ensure template settings are preserved. Signed-off-by: Ryan Johnson <rya@tenthirtyam.org>
1 parent 1f30c27 commit bfdf005

File tree

2 files changed

+32
-5
lines changed

2 files changed

+32
-5
lines changed

builder/vsphere/common/step_hardware.go

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ package common
99
import (
1010
"context"
1111
"fmt"
12-
"reflect"
1312

1413
"github.com/hashicorp/packer-plugin-sdk/multistep"
1514
packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
@@ -147,8 +146,15 @@ func (s *StepConfigureHardware) Run(_ context.Context, state multistep.StateBag)
147146
ui := state.Get("ui").(packersdk.Ui)
148147
vm := state.Get("vm").(driver.VirtualMachine)
149148

150-
if !reflect.DeepEqual(*s.Config, HardwareConfig{}) {
151-
ui.Say("Customizing hardware...")
149+
hasCustomConfig := s.hasCustomHardwareConfig()
150+
151+
// Always run hardware configuration to preserve template settings.
152+
{
153+
if hasCustomConfig {
154+
ui.Say("Customizing hardware...")
155+
} else {
156+
ui.Say("Applying hardware configuration...")
157+
}
152158

153159
var allowedDevices []driver.PCIPassthroughAllowedDevice
154160
for _, device := range s.Config.AllowedDevices {
@@ -184,4 +190,24 @@ func (s *StepConfigureHardware) Run(_ context.Context, state multistep.StateBag)
184190
return multistep.ActionContinue
185191
}
186192

193+
// hasCustomHardwareConfig checks if user provided custom hardware configuration.
194+
func (s *StepConfigureHardware) hasCustomHardwareConfig() bool {
195+
c := s.Config
196+
197+
if c.CPUs != 0 || c.CpuCores != 0 || c.CPUReservation != 0 || c.CPULimit != 0 ||
198+
c.RAM != 0 || c.RAMReservation != 0 || c.RAMReserveAll ||
199+
c.CpuHotAddEnabled || c.MemoryHotAddEnabled ||
200+
c.VideoRAM != 0 || c.Displays != 0 || c.NestedHV ||
201+
c.VGPUProfile != "" || c.Firmware != "" || c.ForceBIOSSetup ||
202+
c.VTPMEnabled || c.VirtualPrecisionClock != "" {
203+
return true
204+
}
205+
206+
if len(c.AllowedDevices) > 0 {
207+
return true
208+
}
209+
210+
return false
211+
}
212+
187213
func (s *StepConfigureHardware) Cleanup(multistep.StateBag) {}

builder/vsphere/common/step_hardware_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,12 @@ func TestStepConfigureHardware_Run(t *testing.T) {
150150
hardwareConfig: driverHardwareConfigFromConfig(basicStepConfigureHardware().Config),
151151
},
152152
{
153-
name: "Don't configure hardware when config is empty",
153+
name: "Configure hardware even when config is empty (preserves template settings)",
154154
step: &StepConfigureHardware{Config: &HardwareConfig{}},
155155
action: multistep.ActionContinue,
156156
configureError: nil,
157-
configureCalled: false,
157+
configureCalled: true,
158+
hardwareConfig: driverHardwareConfigFromConfig(&HardwareConfig{}),
158159
},
159160
{
160161
name: "Halt when configure return error",

0 commit comments

Comments
 (0)