diff --git a/builder/vsphere/clone/config.hcl2spec.go b/builder/vsphere/clone/config.hcl2spec.go index feb4bfeb..3046d7a9 100644 --- a/builder/vsphere/clone/config.hcl2spec.go +++ b/builder/vsphere/clone/config.hcl2spec.go @@ -59,6 +59,7 @@ type FlatConfig struct { RAMReserveAll *bool `mapstructure:"RAM_reserve_all" cty:"RAM_reserve_all" hcl:"RAM_reserve_all"` MemoryHotAddEnabled *bool `mapstructure:"RAM_hot_plug" cty:"RAM_hot_plug" hcl:"RAM_hot_plug"` VideoRAM *int64 `mapstructure:"video_ram" cty:"video_ram" hcl:"video_ram"` + Displays *int32 `mapstructure:"displays" cty:"displays" hcl:"displays"` VGPUProfile *string `mapstructure:"vgpu_profile" cty:"vgpu_profile" hcl:"vgpu_profile"` NestedHV *bool `mapstructure:"NestedHV" cty:"NestedHV" hcl:"NestedHV"` Firmware *string `mapstructure:"firmware" cty:"firmware" hcl:"firmware"` @@ -203,6 +204,7 @@ func (*FlatConfig) HCL2Spec() map[string]hcldec.Spec { "RAM_reserve_all": &hcldec.AttrSpec{Name: "RAM_reserve_all", Type: cty.Bool, Required: false}, "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}, + "displays": &hcldec.AttrSpec{Name: "displays", Type: cty.Number, Required: false}, "vgpu_profile": &hcldec.AttrSpec{Name: "vgpu_profile", Type: cty.String, Required: false}, "NestedHV": &hcldec.AttrSpec{Name: "NestedHV", Type: cty.Bool, Required: false}, "firmware": &hcldec.AttrSpec{Name: "firmware", Type: cty.String, Required: false}, diff --git a/builder/vsphere/common/step_hardware.go b/builder/vsphere/common/step_hardware.go index 5c80b177..3f6e5705 100644 --- a/builder/vsphere/common/step_hardware.go +++ b/builder/vsphere/common/step_hardware.go @@ -32,8 +32,12 @@ type HardwareConfig struct { RAMReserveAll bool `mapstructure:"RAM_reserve_all"` // Enable RAM hot plug setting for virtual machine. Defaults to `false`. MemoryHotAddEnabled bool `mapstructure:"RAM_hot_plug"` - // Amount of video memory in KB. + // Amount of video memory in KB. See [vSphere documentation](https://docs.vmware.com/en/VMware-vSphere/7.0/com.vmware.vsphere.vm_admin.doc/GUID-789C3913-1053-4850-A0F0-E29C3D32B6DA.html) + // for supported maximums. Defaults to 4096 KB. VideoRAM int64 `mapstructure:"video_ram"` + // Number of video displays. See [vSphere documentation](https://docs.vmware.com/en/VMware-vSphere/7.0/com.vmware.vsphere.vm_admin.doc/GUID-789C3913-1053-4850-A0F0-E29C3D32B6DA.html) + // for supported maximums. Defaults to 1. + Displays int32 `mapstructure:"displays"` // vGPU profile for accelerated graphics. See [NVIDIA GRID vGPU documentation](https://docs.nvidia.com/grid/latest/grid-vgpu-user-guide/index.html#configure-vmware-vsphere-vm-with-vgpu) // for examples of profile names. Defaults to none. VGPUProfile string `mapstructure:"vgpu_profile"` @@ -57,6 +61,7 @@ func (c *HardwareConfig) Prepare() []error { 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'")) } + if c.VTPMEnabled && c.Firmware != "efi" && c.Firmware != "efi-secure" { errs = append(errs, fmt.Errorf("'vTPM' could be enabled only when 'firmware' set to 'efi' or 'efi-secure'")) } @@ -87,6 +92,7 @@ func (s *StepConfigureHardware) Run(_ context.Context, state multistep.StateBag) CpuHotAddEnabled: s.Config.CpuHotAddEnabled, MemoryHotAddEnabled: s.Config.MemoryHotAddEnabled, VideoRAM: s.Config.VideoRAM, + Displays: s.Config.Displays, VGPUProfile: s.Config.VGPUProfile, Firmware: s.Config.Firmware, ForceBIOSSetup: s.Config.ForceBIOSSetup, diff --git a/builder/vsphere/common/step_hardware.hcl2spec.go b/builder/vsphere/common/step_hardware.hcl2spec.go index cc2c6c95..a33d0c1c 100644 --- a/builder/vsphere/common/step_hardware.hcl2spec.go +++ b/builder/vsphere/common/step_hardware.hcl2spec.go @@ -20,6 +20,7 @@ type FlatHardwareConfig struct { RAMReserveAll *bool `mapstructure:"RAM_reserve_all" cty:"RAM_reserve_all" hcl:"RAM_reserve_all"` MemoryHotAddEnabled *bool `mapstructure:"RAM_hot_plug" cty:"RAM_hot_plug" hcl:"RAM_hot_plug"` VideoRAM *int64 `mapstructure:"video_ram" cty:"video_ram" hcl:"video_ram"` + Displays *int32 `mapstructure:"displays" cty:"displays" hcl:"displays"` VGPUProfile *string `mapstructure:"vgpu_profile" cty:"vgpu_profile" hcl:"vgpu_profile"` NestedHV *bool `mapstructure:"NestedHV" cty:"NestedHV" hcl:"NestedHV"` Firmware *string `mapstructure:"firmware" cty:"firmware" hcl:"firmware"` @@ -49,6 +50,7 @@ func (*FlatHardwareConfig) HCL2Spec() map[string]hcldec.Spec { "RAM_reserve_all": &hcldec.AttrSpec{Name: "RAM_reserve_all", Type: cty.Bool, Required: false}, "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}, + "displays": &hcldec.AttrSpec{Name: "displays", Type: cty.Number, Required: false}, "vgpu_profile": &hcldec.AttrSpec{Name: "vgpu_profile", Type: cty.String, Required: false}, "NestedHV": &hcldec.AttrSpec{Name: "NestedHV", Type: cty.Bool, Required: false}, "firmware": &hcldec.AttrSpec{Name: "firmware", Type: cty.String, Required: false}, diff --git a/builder/vsphere/driver/vm.go b/builder/vsphere/driver/vm.go index 8bf91218..bb966787 100644 --- a/builder/vsphere/driver/vm.go +++ b/builder/vsphere/driver/vm.go @@ -99,6 +99,7 @@ type HardwareConfig struct { CpuHotAddEnabled bool MemoryHotAddEnabled bool VideoRAM int64 + Displays int32 VGPUProfile string Firmware string ForceBIOSSetup bool @@ -561,7 +562,11 @@ func (vm *VirtualMachineDriver) Configure(config *HardwareConfig) error { confSpec.CpuHotAddEnabled = &config.CpuHotAddEnabled confSpec.MemoryHotAddEnabled = &config.MemoryHotAddEnabled - if config.VideoRAM != 0 { + if config.Displays == 0 { + config.Displays = 1 + } + + if config.VideoRAM != 0 || config.Displays != 0 { devices, err := vm.vm.Device(vm.driver.ctx) if err != nil { return err @@ -571,15 +576,15 @@ func (vm *VirtualMachineDriver) Configure(config *HardwareConfig) error { return err } card := l[0].(*types.VirtualMachineVideoCard) - card.VideoRamSizeInKB = config.VideoRAM - + card.NumDisplays = config.Displays spec := &types.VirtualDeviceConfigSpec{ Device: card, Operation: types.VirtualDeviceConfigSpecOperationEdit, } confSpec.DeviceChange = append(confSpec.DeviceChange, spec) } + if config.VGPUProfile != "" { devices, err := vm.vm.Device(vm.driver.ctx) if err != nil { diff --git a/builder/vsphere/iso/config.hcl2spec.go b/builder/vsphere/iso/config.hcl2spec.go index 9829dd9b..e61dfc20 100644 --- a/builder/vsphere/iso/config.hcl2spec.go +++ b/builder/vsphere/iso/config.hcl2spec.go @@ -57,6 +57,7 @@ type FlatConfig struct { RAMReserveAll *bool `mapstructure:"RAM_reserve_all" cty:"RAM_reserve_all" hcl:"RAM_reserve_all"` MemoryHotAddEnabled *bool `mapstructure:"RAM_hot_plug" cty:"RAM_hot_plug" hcl:"RAM_hot_plug"` VideoRAM *int64 `mapstructure:"video_ram" cty:"video_ram" hcl:"video_ram"` + Displays *int32 `mapstructure:"displays" cty:"displays" hcl:"displays"` VGPUProfile *string `mapstructure:"vgpu_profile" cty:"vgpu_profile" hcl:"vgpu_profile"` NestedHV *bool `mapstructure:"NestedHV" cty:"NestedHV" hcl:"NestedHV"` Firmware *string `mapstructure:"firmware" cty:"firmware" hcl:"firmware"` @@ -203,6 +204,7 @@ func (*FlatConfig) HCL2Spec() map[string]hcldec.Spec { "RAM_reserve_all": &hcldec.AttrSpec{Name: "RAM_reserve_all", Type: cty.Bool, Required: false}, "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}, + "displays": &hcldec.AttrSpec{Name: "displays", Type: cty.Number, Required: false}, "vgpu_profile": &hcldec.AttrSpec{Name: "vgpu_profile", Type: cty.String, Required: false}, "NestedHV": &hcldec.AttrSpec{Name: "NestedHV", Type: cty.Bool, Required: false}, "firmware": &hcldec.AttrSpec{Name: "firmware", Type: cty.String, Required: false}, diff --git a/docs-partials/builder/vsphere/common/HardwareConfig-not-required.mdx b/docs-partials/builder/vsphere/common/HardwareConfig-not-required.mdx index 61282b48..43d6b733 100644 --- a/docs-partials/builder/vsphere/common/HardwareConfig-not-required.mdx +++ b/docs-partials/builder/vsphere/common/HardwareConfig-not-required.mdx @@ -19,7 +19,11 @@ - `RAM_hot_plug` (bool) - Enable RAM hot plug setting for virtual machine. Defaults to `false`. -- `video_ram` (int64) - Amount of video memory in KB. +- `video_ram` (int64) - Amount of video memory in KB. See [vSphere documentation](https://docs.vmware.com/en/VMware-vSphere/7.0/com.vmware.vsphere.vm_admin.doc/GUID-789C3913-1053-4850-A0F0-E29C3D32B6DA.html) + for supported maximums. Defaults to 4096 KB. + +- `displays` (int32) - Number of video displays. See [vSphere documentation](https://docs.vmware.com/en/VMware-vSphere/7.0/com.vmware.vsphere.vm_admin.doc/GUID-789C3913-1053-4850-A0F0-E29C3D32B6DA.html) + for supported maximums. Defaults to 1. - `vgpu_profile` (string) - vGPU profile for accelerated graphics. See [NVIDIA GRID vGPU documentation](https://docs.nvidia.com/grid/latest/grid-vgpu-user-guide/index.html#configure-vmware-vsphere-vm-with-vgpu) for examples of profile names. Defaults to none.