mirror of
https://github.com/bpg/terraform-provider-proxmox.git
synced 2025-07-02 03:22: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:
parent
a546a82928
commit
de3935d462
@ -516,8 +516,9 @@ func getDiskInfo(resp *vms.GetResponseData, d *schema.ResourceData) map[string]*
|
|||||||
v.FileID = &fileID
|
v.FileID = &fileID
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// defensive copy of the loop variable
|
||||||
v.Interface = &k
|
iface := k
|
||||||
|
v.Interface = &iface
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1679,9 +1679,9 @@ func vmCreateClone(ctx context.Context, d *schema.ResourceData, m interface{}) d
|
|||||||
return diag.FromErr(e)
|
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 {
|
if e != nil {
|
||||||
return diag.FromErr(e)
|
return diag.FromErr(e)
|
||||||
}
|
}
|
||||||
@ -1691,29 +1691,33 @@ func vmCreateClone(ctx context.Context, d *schema.ResourceData, m interface{}) d
|
|||||||
diskInterface := diskBlock[mkResourceVirtualEnvironmentVMDiskInterface].(string)
|
diskInterface := diskBlock[mkResourceVirtualEnvironmentVMDiskInterface].(string)
|
||||||
dataStoreID := diskBlock[mkResourceVirtualEnvironmentVMDiskDatastoreID].(string)
|
dataStoreID := diskBlock[mkResourceVirtualEnvironmentVMDiskDatastoreID].(string)
|
||||||
diskSize := diskBlock[mkResourceVirtualEnvironmentVMDiskSize].(int)
|
diskSize := diskBlock[mkResourceVirtualEnvironmentVMDiskSize].(int)
|
||||||
|
prefix := diskDigitPrefix(diskInterface)
|
||||||
|
|
||||||
currentDiskInfo := allDiskInfo[diskInterface]
|
currentDiskInfo := allDiskInfo[diskInterface]
|
||||||
|
configuredDiskInfo := diskDeviceObjects[prefix][diskInterface]
|
||||||
|
|
||||||
if currentDiskInfo == nil {
|
if currentDiskInfo == nil {
|
||||||
diskUpdateBody := &vms.UpdateRequestBody{}
|
diskUpdateBody := &vms.UpdateRequestBody{}
|
||||||
prefix := diskDigitPrefix(diskInterface)
|
|
||||||
|
|
||||||
switch prefix {
|
switch prefix {
|
||||||
case "virtio":
|
case "virtio":
|
||||||
if diskUpdateBody.VirtualIODevices == nil {
|
if diskUpdateBody.VirtualIODevices == nil {
|
||||||
diskUpdateBody.VirtualIODevices = vms.CustomStorageDevices{}
|
diskUpdateBody.VirtualIODevices = vms.CustomStorageDevices{}
|
||||||
}
|
}
|
||||||
diskUpdateBody.VirtualIODevices[diskInterface] = diskDeviceObjects[prefix][diskInterface]
|
|
||||||
|
diskUpdateBody.VirtualIODevices[diskInterface] = configuredDiskInfo
|
||||||
case "sata":
|
case "sata":
|
||||||
if diskUpdateBody.SATADevices == nil {
|
if diskUpdateBody.SATADevices == nil {
|
||||||
diskUpdateBody.SATADevices = vms.CustomStorageDevices{}
|
diskUpdateBody.SATADevices = vms.CustomStorageDevices{}
|
||||||
}
|
}
|
||||||
diskUpdateBody.SATADevices[diskInterface] = diskDeviceObjects[prefix][diskInterface]
|
|
||||||
|
diskUpdateBody.SATADevices[diskInterface] = configuredDiskInfo
|
||||||
case "scsi":
|
case "scsi":
|
||||||
if diskUpdateBody.SCSIDevices == nil {
|
if diskUpdateBody.SCSIDevices == nil {
|
||||||
diskUpdateBody.SCSIDevices = vms.CustomStorageDevices{}
|
diskUpdateBody.SCSIDevices = vms.CustomStorageDevices{}
|
||||||
}
|
}
|
||||||
diskUpdateBody.SCSIDevices[diskInterface] = diskDeviceObjects[prefix][diskInterface]
|
|
||||||
|
diskUpdateBody.SCSIDevices[diskInterface] = configuredDiskInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
e = vmAPI.UpdateVM(ctx, diskUpdateBody)
|
e = vmAPI.UpdateVM(ctx, diskUpdateBody)
|
||||||
|
Loading…
Reference in New Issue
Block a user