Skip to content

Commit 0f46b3a

Browse files
committed
working on read and more testing
1 parent 728b2be commit 0f46b3a

2 files changed

Lines changed: 26 additions & 9 deletions

File tree

builtin/providers/vsphere/resource_vsphere_virtual_machine.go

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -269,8 +269,13 @@ func resourceVSphereVirtualMachineCreate(d *schema.ResourceData, meta interface{
269269
}
270270

271271
if vL, ok := d.GetOk("custom_configuration_parameters"); ok {
272-
if custom_configs, ok := vL.(map[string]types.AnyType); ok {
273-
vm.customConfigurations = custom_configs
272+
if custom_configs, ok := vL.(map[string]interface{}); ok {
273+
custom := make(map[string]types.AnyType)
274+
for k,v := range custom_configs {
275+
custom[k] = v
276+
}
277+
vm.customConfigurations = custom
278+
log.Printf("[DEBUG] custom_configuration_parameters init: %v", vm.customConfigurations)
274279
}
275280
}
276281

@@ -432,14 +437,21 @@ func resourceVSphereVirtualMachineRead(d *schema.ResourceData, meta interface{})
432437
d.Set("memory", mvm.Summary.Config.MemorySizeMB)
433438
d.Set("cpu", mvm.Summary.Config.NumCpu)
434439

435-
if len(mvm.Config.ExtraConfig) > 0 {
440+
log.Printf("[DEBUG] ===============================")
441+
//log.Printf("[DEBUG] Get extra config ===============================")
442+
//log.Printf("[DEBUG] Get extra config %v", mvm.Config)
443+
//log.Printf("[DEBUG] Get extra config %v", mvm.Config.ExtraConfig)
444+
if mvm.Config != nil && mvm.Config.ExtraConfig != nil && len(mvm.Config.ExtraConfig) > 0 {
445+
log.Printf("[DEBUG] reading custom configs")
436446
custom_configs := make(map[string]types.AnyType)
437447
for _, v := range mvm.Config.ExtraConfig {
438448
value := v.GetOptionValue()
439449
custom_configs[value.Key] = value.Value
450+
log.Printf("[DEBUG] reading custom configs %s,%s",value.Key, value.Value)
440451
}
441452
d.Set("custom_configuration_parameters", custom_configs)
442453
}
454+
log.Printf("[DEBUG] ===============================")
443455
d.Set("datastore", rootDatastore)
444456

445457
// Initialize the connection info
@@ -825,6 +837,7 @@ func (vm *virtualMachine) createVirtualMachine(c *govmomi.Client) error {
825837
log.Printf("[DEBUG] virtual machine config spec: %v", configSpec)
826838

827839
// make ExtraConfig
840+
log.Printf("[DEBUG] virtual machine Extra Config spec start")
828841
if len(vm.customConfigurations) > 0 {
829842
var ov []types.BaseOptionValue
830843
for k, v := range vm.customConfigurations {
@@ -834,6 +847,7 @@ func (vm *virtualMachine) createVirtualMachine(c *govmomi.Client) error {
834847
Key: key,
835848
Value: &value,
836849
}
850+
log.Printf("[DEBUG] virtual machine Extra Config spec: %s,%s", k,v)
837851
ov = append(ov, &o)
838852
}
839853
configSpec.ExtraConfig = ov
@@ -1041,6 +1055,8 @@ func (vm *virtualMachine) deployVirtualMachine(c *govmomi.Client) error {
10411055
}
10421056
log.Printf("[DEBUG] virtual machine config spec: %v", configSpec)
10431057

1058+
log.Printf("[DEBUG] starting extra custom config spec: %v", vm.customConfigurations)
1059+
10441060
// make ExtraConfig
10451061
if len(vm.customConfigurations) > 0 {
10461062
var ov []types.BaseOptionValue
@@ -1149,5 +1165,6 @@ func (vm *virtualMachine) deployVirtualMachine(c *govmomi.Client) error {
11491165
return err
11501166
}
11511167
}
1168+
log.Printf("[DEBUG] virtual machine config spec: %v", configSpec)
11521169
return nil
11531170
}

builtin/providers/vsphere/resource_vsphere_virtual_machine_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,9 @@ func TestAccVSphereVirtualMachine_custom_configs(t *testing.T) {
161161
template,
162162
),
163163
Check: resource.ComposeTestCheckFunc(
164-
testAccCheckVSphereVirtualMachineExists("vsphere_virtual_machine.bar", &vm),
164+
testAccCheckVSphereVirtualMachineExists("vsphere_virtual_machine.car", &vm),
165165
resource.TestCheckResourceAttr(
166-
"vsphere_virtual_machine.car", "name", "terraform-test"),
166+
"vsphere_virtual_machine.car", "name", "terraform-test-custom"),
167167
resource.TestCheckResourceAttr(
168168
"vsphere_virtual_machine.car", "vcpu", "2"),
169169
resource.TestCheckResourceAttr(
@@ -181,7 +181,7 @@ func TestAccVSphereVirtualMachine_custom_configs(t *testing.T) {
181181
resource.TestCheckResourceAttr(
182182
"vsphere_virtual_machine.car", "custom_configuration_parameters.num", "42"),
183183
resource.TestCheckResourceAttr(
184-
"vsphere_virtual_machine.bar", "network_interface.0.label", label),
184+
"vsphere_virtual_machine.car", "network_interface.0.label", label),
185185
),
186186
},
187187
},
@@ -299,9 +299,9 @@ resource "vsphere_virtual_machine" "car" {
299299
label = "%s"
300300
}
301301
custom_configuration_parameters {
302-
foo = "bar",
303-
car = "ferrai",
304-
num = 42
302+
"foo" = "bar"
303+
"car" = "ferrai"
304+
"num" = 42
305305
}
306306
disk {
307307
%s

0 commit comments

Comments
 (0)