mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
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:
parent
5cacd788b5
commit
4b9b42dbf0
@ -789,7 +789,6 @@ func resourceVSphereVirtualMachineCreate(d *schema.ResourceData, meta interface{
|
|||||||
if diskSet, ok := vL.(*schema.Set); ok {
|
if diskSet, ok := vL.(*schema.Set); ok {
|
||||||
|
|
||||||
disks := []hardDisk{}
|
disks := []hardDisk{}
|
||||||
hasBootableDisk := false
|
|
||||||
for _, value := range diskSet.List() {
|
for _, value := range diskSet.List() {
|
||||||
disk := value.(map[string]interface{})
|
disk := value.(map[string]interface{})
|
||||||
newDisk := hardDisk{}
|
newDisk := hardDisk{}
|
||||||
@ -799,10 +798,10 @@ func resourceVSphereVirtualMachineCreate(d *schema.ResourceData, meta interface{
|
|||||||
return fmt.Errorf("Cannot specify name of a template")
|
return fmt.Errorf("Cannot specify name of a template")
|
||||||
}
|
}
|
||||||
vm.template = v
|
vm.template = v
|
||||||
if hasBootableDisk {
|
if vm.hasBootableVmdk {
|
||||||
return fmt.Errorf("[ERROR] Only one bootable disk or template may be given")
|
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 != "" {
|
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")
|
return fmt.Errorf("Cannot specify name of a vmdk")
|
||||||
}
|
}
|
||||||
if vBootable, ok := disk["bootable"].(bool); ok {
|
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
|
newDisk.bootable = vBootable
|
||||||
vm.hasBootableVmdk = vBootable
|
vm.hasBootableVmdk = vm.hasBootableVmdk || vBootable
|
||||||
}
|
}
|
||||||
newDisk.vmdkPath = vVmdk
|
newDisk.vmdkPath = vVmdk
|
||||||
}
|
}
|
||||||
|
@ -606,7 +606,12 @@ resource "vsphere_virtual_machine" "with_existing_vmdk" {
|
|||||||
disk {
|
disk {
|
||||||
%s
|
%s
|
||||||
vmdk = "%s"
|
vmdk = "%s"
|
||||||
bootable = true
|
bootable = true
|
||||||
|
}
|
||||||
|
disk {
|
||||||
|
size = 1
|
||||||
|
iops = 500
|
||||||
|
name = "one"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
@ -635,7 +640,7 @@ func TestAccVSphereVirtualMachine_createWithExistingVmdk(t *testing.T) {
|
|||||||
Config: config,
|
Config: config,
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
TestFuncData{vm: vm, label: data.label, vmName: "vsphere_virtual_machine.with_existing_vmdk",
|
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(
|
//resource.TestCheckResourceAttr(
|
||||||
// "vsphere_virtual_machine.with_existing_vmdk", "disk.2393891804.vmdk", vmdk_path),
|
// "vsphere_virtual_machine.with_existing_vmdk", "disk.2393891804.vmdk", vmdk_path),
|
||||||
//resource.TestCheckResourceAttr(
|
//resource.TestCheckResourceAttr(
|
||||||
@ -766,7 +771,7 @@ resource "vsphere_virtual_machine" "ipv4ipv6" {
|
|||||||
disk {
|
disk {
|
||||||
size = 1
|
size = 1
|
||||||
iops = 500
|
iops = 500
|
||||||
name = "one"
|
name = "one"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
Loading…
Reference in New Issue
Block a user