diff --git a/builder/vsphere/clone/config.hcl2spec.go b/builder/vsphere/clone/config.hcl2spec.go index abe33ec9b..6362e2913 100644 --- a/builder/vsphere/clone/config.hcl2spec.go +++ b/builder/vsphere/clone/config.hcl2spec.go @@ -44,6 +44,7 @@ type FlatConfig struct { MemoryHotAddEnabled *bool `mapstructure:"RAM_hot_plug" cty:"RAM_hot_plug"` VideoRAM *int64 `mapstructure:"video_ram" cty:"video_ram"` NestedHV *bool `mapstructure:"NestedHV" cty:"NestedHV"` + Firmware *string `mapstructure:"firmware" cty:"firmware"` ConfigParams map[string]string `mapstructure:"configuration_parameters" cty:"configuration_parameters"` BootOrder *string `mapstructure:"boot_order" cty:"boot_order"` WaitTimeout *string `mapstructure:"ip_wait_timeout" cty:"ip_wait_timeout"` @@ -142,7 +143,12 @@ func (*FlatConfig) HCL2Spec() map[string]hcldec.Spec { "RAM_hot_plug": &hcldec.AttrSpec{Name: "RAM_hot_plug", Type: cty.Bool, Required: false}, "video_ram": &hcldec.AttrSpec{Name: "video_ram", Type: cty.Number, Required: false}, "NestedHV": &hcldec.AttrSpec{Name: "NestedHV", Type: cty.Bool, Required: false}, +<<<<<<< HEAD "configuration_parameters": &hcldec.AttrSpec{Name: "configuration_parameters", Type: cty.Map(cty.String), Required: false}, +======= + "firmware": &hcldec.AttrSpec{Name: "firmware", Type: cty.String, Required: false}, + "configuration_parameters": &hcldec.BlockAttrsSpec{TypeName: "configuration_parameters", ElementType: cty.String, Required: false}, +>>>>>>> builder/vsphere-clone: support firmware changing "boot_order": &hcldec.AttrSpec{Name: "boot_order", Type: cty.String, Required: false}, "ip_wait_timeout": &hcldec.AttrSpec{Name: "ip_wait_timeout", Type: cty.String, Required: false}, "ip_settle_timeout": &hcldec.AttrSpec{Name: "ip_settle_timeout", Type: cty.String, Required: false}, diff --git a/builder/vsphere/common/step_hardware.go b/builder/vsphere/common/step_hardware.go index e7025208a..449f5bcd0 100644 --- a/builder/vsphere/common/step_hardware.go +++ b/builder/vsphere/common/step_hardware.go @@ -36,6 +36,8 @@ type HardwareConfig struct { VideoRAM int64 `mapstructure:"video_ram"` // Enable nested hardware virtualization for VM. Defaults to `false`. NestedHV bool `mapstructure:"NestedHV"` + // Set the Firmware for virtual machine. Supported values: `bios`, `efi`, `efi-secure` or empty string to keep as in template. Defaults to empty string. + Firmware string `mapstructure:"firmware"` } func (c *HardwareConfig) Prepare() []error { @@ -45,6 +47,10 @@ func (c *HardwareConfig) Prepare() []error { errs = append(errs, fmt.Errorf("'RAM_reservation' and 'RAM_reserve_all' cannot be used together")) } + if c.Firmware != "" && c.Firmware != "bios" && c.Firmware != "efi" && c.Firmware != "efi-secure" { + errs = append(errs, fmt.Errorf("'firmware' must be '', 'bios', 'efi' or 'efi-secure'")) + } + return errs } @@ -71,6 +77,7 @@ func (s *StepConfigureHardware) Run(_ context.Context, state multistep.StateBag) CpuHotAddEnabled: s.Config.CpuHotAddEnabled, MemoryHotAddEnabled: s.Config.MemoryHotAddEnabled, VideoRAM: s.Config.VideoRAM, + Firmware: s.Config.Firmware, }) if err != nil { state.Put("error", err) diff --git a/builder/vsphere/common/step_hardware.hcl2spec.go b/builder/vsphere/common/step_hardware.hcl2spec.go index 9640dccc8..9eb600d8a 100644 --- a/builder/vsphere/common/step_hardware.hcl2spec.go +++ b/builder/vsphere/common/step_hardware.hcl2spec.go @@ -9,17 +9,18 @@ import ( // FlatHardwareConfig is an auto-generated flat version of HardwareConfig. // Where the contents of a field with a `mapstructure:,squash` tag are bubbled up. type FlatHardwareConfig struct { - CPUs *int32 `mapstructure:"CPUs" cty:"CPUs"` - CpuCores *int32 `mapstructure:"cpu_cores" cty:"cpu_cores"` - CPUReservation *int64 `mapstructure:"CPU_reservation" cty:"CPU_reservation"` - CPULimit *int64 `mapstructure:"CPU_limit" cty:"CPU_limit"` - CpuHotAddEnabled *bool `mapstructure:"CPU_hot_plug" cty:"CPU_hot_plug"` - RAM *int64 `mapstructure:"RAM" cty:"RAM"` - RAMReservation *int64 `mapstructure:"RAM_reservation" cty:"RAM_reservation"` - RAMReserveAll *bool `mapstructure:"RAM_reserve_all" cty:"RAM_reserve_all"` - MemoryHotAddEnabled *bool `mapstructure:"RAM_hot_plug" cty:"RAM_hot_plug"` - VideoRAM *int64 `mapstructure:"video_ram" cty:"video_ram"` - NestedHV *bool `mapstructure:"NestedHV" cty:"NestedHV"` + CPUs *int32 `mapstructure:"CPUs" cty:"CPUs"` + CpuCores *int32 `mapstructure:"cpu_cores" cty:"cpu_cores"` + CPUReservation *int64 `mapstructure:"CPU_reservation" cty:"CPU_reservation"` + CPULimit *int64 `mapstructure:"CPU_limit" cty:"CPU_limit"` + CpuHotAddEnabled *bool `mapstructure:"CPU_hot_plug" cty:"CPU_hot_plug"` + RAM *int64 `mapstructure:"RAM" cty:"RAM"` + RAMReservation *int64 `mapstructure:"RAM_reservation" cty:"RAM_reservation"` + RAMReserveAll *bool `mapstructure:"RAM_reserve_all" cty:"RAM_reserve_all"` + MemoryHotAddEnabled *bool `mapstructure:"RAM_hot_plug" cty:"RAM_hot_plug"` + VideoRAM *int64 `mapstructure:"video_ram" cty:"video_ram"` + NestedHV *bool `mapstructure:"NestedHV" cty:"NestedHV"` + Firmware *string `mapstructure:"firmware" cty:"firmware"` } // FlatMapstructure returns a new FlatHardwareConfig. @@ -45,6 +46,7 @@ func (*FlatHardwareConfig) HCL2Spec() map[string]hcldec.Spec { "RAM_hot_plug": &hcldec.AttrSpec{Name: "RAM_hot_plug", Type: cty.Bool, Required: false}, "video_ram": &hcldec.AttrSpec{Name: "video_ram", Type: cty.Number, Required: false}, "NestedHV": &hcldec.AttrSpec{Name: "NestedHV", Type: cty.Bool, Required: false}, + "firmware": &hcldec.AttrSpec{Name: "firmware", Type: cty.String, Required: false}, } return s } diff --git a/builder/vsphere/driver/vm.go b/builder/vsphere/driver/vm.go index 03c58d3bb..1736bd892 100644 --- a/builder/vsphere/driver/vm.go +++ b/builder/vsphere/driver/vm.go @@ -47,6 +47,7 @@ type HardwareConfig struct { CpuHotAddEnabled bool MemoryHotAddEnabled bool VideoRAM int64 + Firmware string } type NIC struct { @@ -355,6 +356,15 @@ func (vm *VirtualMachine) Configure(config *HardwareConfig) error { confSpec.DeviceChange = append(confSpec.DeviceChange, spec) } + if config.Firmware == "efi-secure" || config.Firmware == "efi" { + confSpec.Firmware = "efi" + confSpec.BootOptions = &types.VirtualMachineBootOptions{ + EfiSecureBootEnabled: types.NewBool(config.Firmware == "efi-secure"), + } + } else if config.Firmware != "" { + confSpec.Firmware = config.Firmware + } + task, err := vm.vm.Reconfigure(vm.driver.ctx, confSpec) if err != nil { return err diff --git a/website/pages/partials/builder/vsphere/common/HardwareConfig-not-required.mdx b/website/pages/partials/builder/vsphere/common/HardwareConfig-not-required.mdx index 7990d5b06..4e309a7d6 100644 --- a/website/pages/partials/builder/vsphere/common/HardwareConfig-not-required.mdx +++ b/website/pages/partials/builder/vsphere/common/HardwareConfig-not-required.mdx @@ -22,4 +22,6 @@ - `video_ram` (int64) - Amount of video memory in MB. - `NestedHV` (bool) - Enable nested hardware virtualization for VM. Defaults to `false`. + +- `firmware` (string) - Set the Firmware for virtual machine. Supported values: `bios`, `efi`, `efi-secure` or empty string to keep as in template. Defaults to empty string. \ No newline at end of file