From b47d1cda7c8da6cf8ad0cb69148550dcb17db37e Mon Sep 17 00:00:00 2001 From: Chris Love Date: Sun, 8 Nov 2015 18:02:07 -0700 Subject: [PATCH] adding capability to set custom configuration value in virtual machines --- .../resource_vsphere_virtual_machine.go | 35 ++++++++++--------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/builtin/providers/vsphere/resource_vsphere_virtual_machine.go b/builtin/providers/vsphere/resource_vsphere_virtual_machine.go index 338c95301..dbaa3f884 100644 --- a/builtin/providers/vsphere/resource_vsphere_virtual_machine.go +++ b/builtin/providers/vsphere/resource_vsphere_virtual_machine.go @@ -269,13 +269,8 @@ func resourceVSphereVirtualMachineCreate(d *schema.ResourceData, meta interface{ } if vL, ok := d.GetOk("custom_configuration_parameters"); ok { - if custom_configs, ok := vL.(map[string]interface{}); ok { - custom := make(map[string]types.AnyType) - for k,v := range custom_configs { - custom[k] = v - } - vm.customConfigurations = custom - log.Printf("[DEBUG] custom_configuration_parameters init: %v", vm.customConfigurations) + if custom_configs, ok := vL.(map[string]types.AnyType); ok { + vm.customConfigurations = custom_configs } } @@ -437,21 +432,14 @@ func resourceVSphereVirtualMachineRead(d *schema.ResourceData, meta interface{}) d.Set("memory", mvm.Summary.Config.MemorySizeMB) d.Set("cpu", mvm.Summary.Config.NumCpu) - log.Printf("[DEBUG] ===============================") - //log.Printf("[DEBUG] Get extra config ===============================") - //log.Printf("[DEBUG] Get extra config %v", mvm.Config) - //log.Printf("[DEBUG] Get extra config %v", mvm.Config.ExtraConfig) - if mvm.Config != nil && mvm.Config.ExtraConfig != nil && len(mvm.Config.ExtraConfig) > 0 { - log.Printf("[DEBUG] reading custom configs") - custom_configs := make(map[string]types.AnyType) + if mvm.Config && len(mvm.Config.ExtraConfig) > 0 { + custom_configs := make(map[string]string) for _, v := range mvm.Config.ExtraConfig { value := v.GetOptionValue() custom_configs[value.Key] = value.Value - log.Printf("[DEBUG] reading custom configs %s,%s",value.Key, value.Value) } d.Set("custom_configuration_parameters", custom_configs) } - log.Printf("[DEBUG] ===============================") d.Set("datastore", rootDatastore) // Initialize the connection info @@ -837,6 +825,21 @@ func (vm *virtualMachine) createVirtualMachine(c *govmomi.Client) error { log.Printf("[DEBUG] virtual machine config spec: %v", configSpec) // make ExtraConfig + if len(vm.customConfigurations) > 0 { + var ov []types.BaseOptionValue + for k, v := range vm.customConfigurations { + key := k + value := v + o := types.OptionValue{ + Key: key, + Value: &value, + } + ov = append(ov, &o) + } + configSpec.ExtraConfig = ov + log.Printf("[DEBUG] virtual machine Extra Config spec: %v", configSpec.ExtraConfig) + } + log.Printf("[DEBUG] virtual machine Extra Config spec start") if len(vm.customConfigurations) > 0 { var ov []types.BaseOptionValue