Fixes the hasBootableVmdk flag when attaching multiple disks (#7804)

The hasBootableFlag logic had a bug where it would only be set properly
if the bootable disk was the last specified.  Adding some bool logic
resolves the issue.  Also adding check to ensure only one bootable disk
is given, and cleaning up a redundant var.
This commit is contained in:
Dan Allegood 2016-07-26 16:25:56 -07:00 committed by Paul Stack
parent 5cacd788b5
commit 4b9b42dbf0
2 changed files with 14 additions and 8 deletions

View File

@ -789,7 +789,6 @@ func resourceVSphereVirtualMachineCreate(d *schema.ResourceData, meta interface{
if diskSet, ok := vL.(*schema.Set); ok {
disks := []hardDisk{}
hasBootableDisk := false
for _, value := range diskSet.List() {
disk := value.(map[string]interface{})
newDisk := hardDisk{}
@ -799,10 +798,10 @@ func resourceVSphereVirtualMachineCreate(d *schema.ResourceData, meta interface{
return fmt.Errorf("Cannot specify name of a template")
}
vm.template = v
if hasBootableDisk {
if vm.hasBootableVmdk {
return fmt.Errorf("[ERROR] Only one bootable disk or template may be given")
}
hasBootableDisk = true
vm.hasBootableVmdk = true
}
if v, ok := disk["type"].(string); ok && v != "" {
@ -846,9 +845,11 @@ func resourceVSphereVirtualMachineCreate(d *schema.ResourceData, meta interface{
return fmt.Errorf("Cannot specify name of a vmdk")
}
if vBootable, ok := disk["bootable"].(bool); ok {
hasBootableDisk = true
if vBootable && vm.hasBootableVmdk {
return fmt.Errorf("[ERROR] Only one bootable disk or template may be given")
}
newDisk.bootable = vBootable
vm.hasBootableVmdk = vBootable
vm.hasBootableVmdk = vm.hasBootableVmdk || vBootable
}
newDisk.vmdkPath = vVmdk
}

View File

@ -608,6 +608,11 @@ resource "vsphere_virtual_machine" "with_existing_vmdk" {
vmdk = "%s"
bootable = true
}
disk {
size = 1
iops = 500
name = "one"
}
}
`
@ -635,7 +640,7 @@ func TestAccVSphereVirtualMachine_createWithExistingVmdk(t *testing.T) {
Config: config,
Check: resource.ComposeTestCheckFunc(
TestFuncData{vm: vm, label: data.label, vmName: "vsphere_virtual_machine.with_existing_vmdk",
vmResource: "terraform-test-with-existing-vmdk"}.testCheckFuncBasic(),
vmResource: "terraform-test-with-existing-vmdk", numDisks: "2"}.testCheckFuncBasic(),
//resource.TestCheckResourceAttr(
// "vsphere_virtual_machine.with_existing_vmdk", "disk.2393891804.vmdk", vmdk_path),
//resource.TestCheckResourceAttr(