diff --git a/builder/vmware/common/hw_config.go b/builder/vmware/common/hw_config.go index d740025c2..588d295f1 100644 --- a/builder/vmware/common/hw_config.go +++ b/builder/vmware/common/hw_config.go @@ -14,6 +14,7 @@ type HWConfig struct { // cpu information CpuCount int `mapstructure:"cpus"` MemorySize int `mapstructure:"memory"` + CoreCount int `mapstructure:"cores"` // network type and adapter Network string `mapstructure:"network"` @@ -40,6 +41,11 @@ func (c *HWConfig) Prepare(ctx *interpolate.Context) []error { errs = append(errs, fmt.Errorf("An invalid amount of memory was specified (memory < 0): %d", c.MemorySize)) } + // Hardware and cpu options + if c.CoreCount < 0 { + errs = append(errs, fmt.Errorf("An invalid number of cores was specified (cores < 0): %d", c.CoreCount)) + } + // Peripherals if !c.Sound { c.Sound = false diff --git a/builder/vmware/common/hw_config_test.go b/builder/vmware/common/hw_config_test.go index be884b144..3532dc1b9 100644 --- a/builder/vmware/common/hw_config_test.go +++ b/builder/vmware/common/hw_config_test.go @@ -8,6 +8,7 @@ import ( func testHWConfig() *HWConfig { return &HWConfig{ CpuCount: 1, + CoreCount: 1, MemorySize: 512, Sound: true, @@ -26,6 +27,10 @@ func TestHWConfigPrepare(t *testing.T) { t.Errorf("bad cpu count: %d", c.CpuCount) } + if c.CoreCount < 0 { + t.Errorf("bad core count: %d", c.CoreCount) + } + if c.MemorySize < 0 { t.Errorf("bad memory size: %d", c.MemorySize) } diff --git a/builder/vmware/iso/step_create_vmx.go b/builder/vmware/iso/step_create_vmx.go index ba9c273b6..3e95a13e8 100644 --- a/builder/vmware/iso/step_create_vmx.go +++ b/builder/vmware/iso/step_create_vmx.go @@ -423,12 +423,19 @@ func (s *stepCreateVMX) Run(_ context.Context, state multistep.StateBag) multist s.tempDir = vmxDir } - /// Now to handle options that will modify the template + /// Now to handle options that will modify the template without using "vmxTemplateData" vmxData := vmwcommon.ParseVMX(vmxContents) + + // If no cpus were specified, then remove the entry to use the default if vmxData["numvcpus"] == "" { delete(vmxData, "numvcpus") } + // If some number of cores were specified, then update "cpuid.coresPerSocket" with the requested value + if config.HWConfig.CoreCount > 0 { + vmxData["cpuid.corespersocket"] = strconv.Itoa(config.HWConfig.CoreCount) + } + /// Write the vmxData to the vmxPath vmxPath := filepath.Join(vmxDir, config.VMName+".vmx") if err := vmwcommon.WriteVMX(vmxPath, vmxData); err != nil { diff --git a/website/source/docs/builders/vmware-iso.html.md.erb b/website/source/docs/builders/vmware-iso.html.md.erb index 12d0d77cc..0a2411d79 100644 --- a/website/source/docs/builders/vmware-iso.html.md.erb +++ b/website/source/docs/builders/vmware-iso.html.md.erb @@ -100,6 +100,9 @@ builder. - `cpus` (number) - The number of cpus to use when building the VM. +- `cores` (number) - The number of cores per socket to use when building the VM. + This corresponds to the `cpuid.coresPerSocket` option in the .vmx file. + - `cdrom_adapter_type` (string) - The adapter type (or bus) that will be used by the cdrom device. This is chosen by default based on the disk adapter type. VMware tends to lean towards `ide` for the cdrom device unless