diff --git a/builder/proxmox/config.go b/builder/proxmox/config.go index 7a2c045f9..6cab9a936 100644 --- a/builder/proxmox/config.go +++ b/builder/proxmox/config.go @@ -1,4 +1,4 @@ -//go:generate mapstructure-to-hcl2 -type Config,nicConfig,diskConfig +//go:generate mapstructure-to-hcl2 -type Config,nicConfig,diskConfig,vgaConfig package proxmox @@ -45,6 +45,7 @@ type Config struct { CPUType string `mapstructure:"cpu_type"` Sockets int `mapstructure:"sockets"` OS string `mapstructure:"os"` + VGA vgaConfig `mapstructure:"vga"` NICs []nicConfig `mapstructure:"network_adapters"` Disks []diskConfig `mapstructure:"disks"` ISOFile string `mapstructure:"iso_file"` @@ -75,6 +76,10 @@ type diskConfig struct { CacheMode string `mapstructure:"cache_mode"` DiskFormat string `mapstructure:"format"` } +type vgaConfig struct { + Type string `mapstructure:"type"` + Memory int `mapstructure:"memory"` +} func (c *Config) Prepare(raws ...interface{}) ([]string, error) { // Agent defaults to true diff --git a/builder/proxmox/config.hcl2spec.go b/builder/proxmox/config.hcl2spec.go index dc4a7dc39..d15a62155 100644 --- a/builder/proxmox/config.hcl2spec.go +++ b/builder/proxmox/config.hcl2spec.go @@ -1,4 +1,4 @@ -// Code generated by "mapstructure-to-hcl2 -type Config,nicConfig,diskConfig"; DO NOT EDIT. +// Code generated by "mapstructure-to-hcl2 -type Config,nicConfig,diskConfig,vgaConfig"; DO NOT EDIT. package proxmox import ( @@ -84,6 +84,7 @@ type FlatConfig struct { CPUType *string `mapstructure:"cpu_type" cty:"cpu_type"` Sockets *int `mapstructure:"sockets" cty:"sockets"` OS *string `mapstructure:"os" cty:"os"` + VGA *FlatvgaConfig `mapstructure:"vga" cty:"vga"` NICs []FlatnicConfig `mapstructure:"network_adapters" cty:"network_adapters"` Disks []FlatdiskConfig `mapstructure:"disks" cty:"disks"` ISOFile *string `mapstructure:"iso_file" cty:"iso_file"` @@ -182,6 +183,7 @@ func (*FlatConfig) HCL2Spec() map[string]hcldec.Spec { "cpu_type": &hcldec.AttrSpec{Name: "cpu_type", Type: cty.String, Required: false}, "sockets": &hcldec.AttrSpec{Name: "sockets", Type: cty.Number, Required: false}, "os": &hcldec.AttrSpec{Name: "os", Type: cty.String, Required: false}, + "vga": &hcldec.BlockSpec{TypeName: "vga", Nested: hcldec.ObjectSpec((*FlatvgaConfig)(nil).HCL2Spec())}, "network_adapters": &hcldec.BlockListSpec{TypeName: "network_adapters", Nested: hcldec.ObjectSpec((*FlatnicConfig)(nil).HCL2Spec())}, "disks": &hcldec.BlockListSpec{TypeName: "disks", Nested: hcldec.ObjectSpec((*FlatdiskConfig)(nil).HCL2Spec())}, "iso_file": &hcldec.AttrSpec{Name: "iso_file", Type: cty.String, Required: false}, @@ -256,3 +258,28 @@ func (*FlatnicConfig) HCL2Spec() map[string]hcldec.Spec { } return s } + +// FlatvgaConfig is an auto-generated flat version of vgaConfig. +// Where the contents of a field with a `mapstructure:,squash` tag are bubbled up. +type FlatvgaConfig struct { + Type *string `mapstructure:"type" cty:"type"` + Memory *int `mapstructure:"memory" cty:"memory"` +} + +// FlatMapstructure returns a new FlatvgaConfig. +// FlatvgaConfig is an auto-generated flat version of vgaConfig. +// Where the contents a fields with a `mapstructure:,squash` tag are bubbled up. +func (*vgaConfig) FlatMapstructure() interface{ HCL2Spec() map[string]hcldec.Spec } { + return new(FlatvgaConfig) +} + +// HCL2Spec returns the hcl spec of a vgaConfig. +// This spec is used by HCL to read the fields of vgaConfig. +// The decoded values from this spec will then be applied to a FlatvgaConfig. +func (*FlatvgaConfig) HCL2Spec() map[string]hcldec.Spec { + s := map[string]hcldec.Spec{ + "type": &hcldec.AttrSpec{Name: "type", Type: cty.String, Required: false}, + "memory": &hcldec.AttrSpec{Name: "memory", Type: cty.Number, Required: false}, + } + return s +} diff --git a/builder/proxmox/step_start_vm.go b/builder/proxmox/step_start_vm.go index 453798917..36f214d00 100644 --- a/builder/proxmox/step_start_vm.go +++ b/builder/proxmox/step_start_vm.go @@ -39,6 +39,7 @@ func (s *stepStartVM) Run(ctx context.Context, state multistep.StateBag) multist QemuCores: c.Cores, QemuSockets: c.Sockets, QemuOs: c.OS, + QemuVga: generateProxmoxVga(c.VGA), QemuIso: isoFile, QemuNetworks: generateProxmoxNetworkAdapters(c.NICs), QemuDisks: generateProxmoxDisks(c.Disks), @@ -118,6 +119,15 @@ func generateProxmoxDisks(disks []diskConfig) proxmox.QemuDevices { } return devs } +func generateProxmoxVga(vga vgaConfig) proxmox.QemuDevice { + dev := make(proxmox.QemuDevice) + setDeviceParamIfDefined(dev, "type", vga.Type) + + if vga.Memory > 0 { + dev["memory"] = vga.Memory + } + return dev +} func setDeviceParamIfDefined(dev proxmox.QemuDevice, key, value string) { if value != "" { diff --git a/website/source/docs/builders/proxmox.html.md b/website/source/docs/builders/proxmox.html.md index 6abc0e123..b99747e15 100644 --- a/website/source/docs/builders/proxmox.html.md +++ b/website/source/docs/builders/proxmox.html.md @@ -95,6 +95,21 @@ builder. `wvista`, `win7`, `win8`, `win10`, `l24` (Linux 2.4), `l26` (Linux 2.6+), `solaris` or `other`. Defaults to `other`. +- `vga` (object) - The graphics adapter to use. Example: + + ```json + { + "type": "vmware", + "memory": 32 + } + ``` + + - `type` (string) - Can be `cirrus`, `none`, `qxl`,`qxl2`, `qxl3`, + `qxl4`, `serial0`, `serial1`, `serial2`, `serial3`, `std`, `virtio`, `vmware`. + Defaults to `std`. + + - `memory` (int) - How much memory to assign. + - `network_adapters` (array of objects) - Network adapters attached to the virtual machine. Example: