Refreshing devices list after adding a disk or cdrom controller (#7167)

Also taking out an unnecessary ForceNew on controller_type as well
as correcting a reference to controller_type in Update case.
This commit is contained in:
dkalleg 2016-06-29 11:47:56 -07:00 committed by Paul Stack
parent 7c9621acc0
commit ab92fa4dff
1 changed files with 15 additions and 4 deletions

View File

@ -414,7 +414,6 @@ func resourceVSphereVirtualMachine() *schema.Resource {
Type: schema.TypeString, Type: schema.TypeString,
Optional: true, Optional: true,
Default: "scsi", Default: "scsi",
ForceNew: true,
ValidateFunc: func(v interface{}, k string) (ws []string, errors []error) { ValidateFunc: func(v interface{}, k string) (ws []string, errors []error) {
value := v.(string) value := v.(string)
if value != "scsi" && value != "ide" { if value != "scsi" && value != "ide" {
@ -540,7 +539,7 @@ func resourceVSphereVirtualMachineUpdate(d *schema.ResourceData, meta interface{
size = int64(disk["size"].(int)) size = int64(disk["size"].(int))
} }
iops := int64(disk["iops"].(int)) iops := int64(disk["iops"].(int))
controller_type := disk["controller"].(string) controller_type := disk["controller_type"].(string)
var mo mo.VirtualMachine var mo mo.VirtualMachine
vm.Properties(context.TODO(), vm.Reference(), []string{"summary", "config"}, &mo) vm.Properties(context.TODO(), vm.Reference(), []string{"summary", "config"}, &mo)
@ -1153,9 +1152,15 @@ func addHardDisk(vm *object.VirtualMachine, size, iops int64, diskType string, d
} }
vm.AddDevice(context.TODO(), c) vm.AddDevice(context.TODO(), c)
// Update our devices list
devices, err := vm.Device(context.TODO())
if err != nil {
return err
}
controller, err = devices.FindDiskController(controller_type) controller, err = devices.FindDiskController(controller_type)
if err != nil { if err != nil {
return fmt.Errorf("[ERROR] Could not find the controller we just created") log.Printf("[ERROR] Could not find the new %v controller: %v", controller_type, err)
return err
} }
} }
@ -1229,9 +1234,15 @@ func addCdrom(vm *object.VirtualMachine, datastore, path string) error {
return fmt.Errorf("[ERROR] Controller type could not be asserted") return fmt.Errorf("[ERROR] Controller type could not be asserted")
} }
vm.AddDevice(context.TODO(), c) vm.AddDevice(context.TODO(), c)
// Update our devices list
devices, err := vm.Device(context.TODO())
if err != nil {
return err
}
controller, err = devices.FindIDEController("") controller, err = devices.FindIDEController("")
if err != nil { if err != nil {
return fmt.Errorf("[ERROR] Could not find the controller we just created") log.Printf("[ERROR] Could not find the new disk IDE controller: %v", err)
return err
} }
} }
log.Printf("[DEBUG] ide controller: %#v", controller) log.Printf("[DEBUG] ide controller: %#v", controller)