From 89fb8f0d3ea8e3400544328bb18a0cbf9bb7a52f Mon Sep 17 00:00:00 2001 From: Megan Marsh Date: Tue, 27 Nov 2018 15:43:48 -0800 Subject: [PATCH] fix defaulting/lack thereof for cpu count and memory in vmware template --- builder/vmware/iso/step_create_vmx.go | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/builder/vmware/iso/step_create_vmx.go b/builder/vmware/iso/step_create_vmx.go index 5aca4485f..4fa5254f8 100644 --- a/builder/vmware/iso/step_create_vmx.go +++ b/builder/vmware/iso/step_create_vmx.go @@ -315,6 +315,18 @@ func (s *stepCreateVMX) Run(_ context.Context, state multistep.StateBag) multist templateData.Serial_Host = "" templateData.Serial_Auto = "FALSE" + // Set the number of cpus if it was specified + if config.HWConfig.CpuCount > 0 { + templateData.CpuCount = strconv.Itoa(config.HWConfig.CpuCount) + } + + // Apply the memory size that was specified + if config.HWConfig.MemorySize > 0 { + templateData.MemorySize = strconv.Itoa(config.HWConfig.MemorySize) + } else { + templateData.MemorySize = "512" + } + switch serial.Union.(type) { case *vmwcommon.SerialConfigPipe: templateData.Serial_Type = "pipe" @@ -412,15 +424,8 @@ func (s *stepCreateVMX) Run(_ context.Context, state multistep.StateBag) multist /// Now to handle options that will modify the template vmxData := vmwcommon.ParseVMX(vmxContents) - - // Set the number of cpus if it was specified - if config.HWConfig.CpuCount > 0 { - vmxData["numvcpus"] = strconv.Itoa(config.HWConfig.CpuCount) - } - - // Apply the memory size that was specified - if config.HWConfig.MemorySize > 0 { - vmxData["memsize"] = strconv.Itoa(config.HWConfig.MemorySize) + if vmxData["numvcpus"] == "" { + delete(vmxData, "numvcpus") } /// Write the vmxData to the vmxPath