0
0
mirror of https://github.com/bpg/terraform-provider-proxmox.git synced 2025-07-01 19:12:59 +00:00

fix(vm): fix incorrect disk interface ref when reading VM info from PVE (#365)

Fix a minor bug in `vmGetDiskDeviceObjects(...)` that was discovered during investigation of #360.
This commit is contained in:
Pavel Boldyrev 2023-06-06 07:45:03 -04:00 committed by GitHub
parent a546a82928
commit de3935d462
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 8 deletions

View File

@ -516,8 +516,9 @@ func getDiskInfo(resp *vms.GetResponseData, d *schema.ResourceData) map[string]*
v.FileID = &fileID
}
}
v.Interface = &k
// defensive copy of the loop variable
iface := k
v.Interface = &iface
}
}

View File

@ -1679,9 +1679,9 @@ func vmCreateClone(ctx context.Context, d *schema.ResourceData, m interface{}) d
return diag.FromErr(e)
}
allDiskInfo := getDiskInfo(vmConfig, d)
allDiskInfo := getDiskInfo(vmConfig, d) // from the cloned VM
diskDeviceObjects, e := vmGetDiskDeviceObjects(d, nil)
diskDeviceObjects, e := vmGetDiskDeviceObjects(d, nil) // from the resource config
if e != nil {
return diag.FromErr(e)
}
@ -1691,29 +1691,33 @@ func vmCreateClone(ctx context.Context, d *schema.ResourceData, m interface{}) d
diskInterface := diskBlock[mkResourceVirtualEnvironmentVMDiskInterface].(string)
dataStoreID := diskBlock[mkResourceVirtualEnvironmentVMDiskDatastoreID].(string)
diskSize := diskBlock[mkResourceVirtualEnvironmentVMDiskSize].(int)
prefix := diskDigitPrefix(diskInterface)
currentDiskInfo := allDiskInfo[diskInterface]
configuredDiskInfo := diskDeviceObjects[prefix][diskInterface]
if currentDiskInfo == nil {
diskUpdateBody := &vms.UpdateRequestBody{}
prefix := diskDigitPrefix(diskInterface)
switch prefix {
case "virtio":
if diskUpdateBody.VirtualIODevices == nil {
diskUpdateBody.VirtualIODevices = vms.CustomStorageDevices{}
}
diskUpdateBody.VirtualIODevices[diskInterface] = diskDeviceObjects[prefix][diskInterface]
diskUpdateBody.VirtualIODevices[diskInterface] = configuredDiskInfo
case "sata":
if diskUpdateBody.SATADevices == nil {
diskUpdateBody.SATADevices = vms.CustomStorageDevices{}
}
diskUpdateBody.SATADevices[diskInterface] = diskDeviceObjects[prefix][diskInterface]
diskUpdateBody.SATADevices[diskInterface] = configuredDiskInfo
case "scsi":
if diskUpdateBody.SCSIDevices == nil {
diskUpdateBody.SCSIDevices = vms.CustomStorageDevices{}
}
diskUpdateBody.SCSIDevices[diskInterface] = diskDeviceObjects[prefix][diskInterface]
diskUpdateBody.SCSIDevices[diskInterface] = configuredDiskInfo
}
e = vmAPI.UpdateVM(ctx, diskUpdateBody)