working on read and more testing
This commit is contained in:
parent
106b126448
commit
0bf8ffd043
|
@ -269,8 +269,13 @@ func resourceVSphereVirtualMachineCreate(d *schema.ResourceData, meta interface{
|
|||
}
|
||||
|
||||
if vL, ok := d.GetOk("custom_configuration_parameters"); ok {
|
||||
if custom_configs, ok := vL.(map[string]types.AnyType); ok {
|
||||
vm.customConfigurations = custom_configs
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -432,14 +437,21 @@ func resourceVSphereVirtualMachineRead(d *schema.ResourceData, meta interface{})
|
|||
d.Set("memory", mvm.Summary.Config.MemorySizeMB)
|
||||
d.Set("cpu", mvm.Summary.Config.NumCpu)
|
||||
|
||||
if len(mvm.Config.ExtraConfig) > 0 {
|
||||
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)
|
||||
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
|
||||
|
@ -825,6 +837,7 @@ func (vm *virtualMachine) createVirtualMachine(c *govmomi.Client) error {
|
|||
log.Printf("[DEBUG] virtual machine config spec: %v", configSpec)
|
||||
|
||||
// make ExtraConfig
|
||||
log.Printf("[DEBUG] virtual machine Extra Config spec start")
|
||||
if len(vm.customConfigurations) > 0 {
|
||||
var ov []types.BaseOptionValue
|
||||
for k, v := range vm.customConfigurations {
|
||||
|
@ -834,6 +847,7 @@ func (vm *virtualMachine) createVirtualMachine(c *govmomi.Client) error {
|
|||
Key: key,
|
||||
Value: &value,
|
||||
}
|
||||
log.Printf("[DEBUG] virtual machine Extra Config spec: %s,%s", k,v)
|
||||
ov = append(ov, &o)
|
||||
}
|
||||
configSpec.ExtraConfig = ov
|
||||
|
@ -1041,6 +1055,8 @@ func (vm *virtualMachine) deployVirtualMachine(c *govmomi.Client) error {
|
|||
}
|
||||
log.Printf("[DEBUG] virtual machine config spec: %v", configSpec)
|
||||
|
||||
log.Printf("[DEBUG] starting extra custom config spec: %v", vm.customConfigurations)
|
||||
|
||||
// make ExtraConfig
|
||||
if len(vm.customConfigurations) > 0 {
|
||||
var ov []types.BaseOptionValue
|
||||
|
@ -1149,5 +1165,6 @@ func (vm *virtualMachine) deployVirtualMachine(c *govmomi.Client) error {
|
|||
return err
|
||||
}
|
||||
}
|
||||
log.Printf("[DEBUG] virtual machine config spec: %v", configSpec)
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -161,9 +161,9 @@ func TestAccVSphereVirtualMachine_custom_configs(t *testing.T) {
|
|||
template,
|
||||
),
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testAccCheckVSphereVirtualMachineExists("vsphere_virtual_machine.bar", &vm),
|
||||
testAccCheckVSphereVirtualMachineExists("vsphere_virtual_machine.car", &vm),
|
||||
resource.TestCheckResourceAttr(
|
||||
"vsphere_virtual_machine.car", "name", "terraform-test"),
|
||||
"vsphere_virtual_machine.car", "name", "terraform-test-custom"),
|
||||
resource.TestCheckResourceAttr(
|
||||
"vsphere_virtual_machine.car", "vcpu", "2"),
|
||||
resource.TestCheckResourceAttr(
|
||||
|
@ -181,7 +181,7 @@ func TestAccVSphereVirtualMachine_custom_configs(t *testing.T) {
|
|||
resource.TestCheckResourceAttr(
|
||||
"vsphere_virtual_machine.car", "custom_configuration_parameters.num", "42"),
|
||||
resource.TestCheckResourceAttr(
|
||||
"vsphere_virtual_machine.bar", "network_interface.0.label", label),
|
||||
"vsphere_virtual_machine.car", "network_interface.0.label", label),
|
||||
),
|
||||
},
|
||||
},
|
||||
|
@ -299,9 +299,9 @@ resource "vsphere_virtual_machine" "car" {
|
|||
label = "%s"
|
||||
}
|
||||
custom_configuration_parameters {
|
||||
foo = "bar",
|
||||
car = "ferrai",
|
||||
num = 42
|
||||
"foo" = "bar"
|
||||
"car" = "ferrai"
|
||||
"num" = 42
|
||||
}
|
||||
disk {
|
||||
%s
|
||||
|
|
Loading…
Reference in New Issue