Skip to content

Commit

Permalink
fix: disk resizing issue
Browse files Browse the repository at this point in the history
  • Loading branch information
danitso-dp committed Feb 13, 2021
1 parent fc655f2 commit 5871fff
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
BUG FIXES:

* resource/virtual_environment_vm: Fix `disk.file_id` diff issue
* resource/virtual_environment_vm: Fix disk resizing issue

OTHER:

Expand Down
24 changes: 20 additions & 4 deletions proxmoxtf/resource_virtual_environment_vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -1413,6 +1413,7 @@ func resourceVirtualEnvironmentVMCreateClone(d *schema.ResourceData, m interface
if currentDiskInfo == nil {
diskUpdateBody := &proxmox.VirtualEnvironmentVMUpdateRequestBody{}
prefix := diskDigitPrefix(diskInterface)

switch prefix {
case "virtio":
if diskUpdateBody.VirtualIODevices == nil {
Expand All @@ -1432,6 +1433,7 @@ func resourceVirtualEnvironmentVMCreateClone(d *schema.ResourceData, m interface
}

err = veClient.UpdateVM(nodeName, vmID, diskUpdateBody)

if err != nil {
return err
}
Expand All @@ -1450,6 +1452,7 @@ func resourceVirtualEnvironmentVMCreateClone(d *schema.ResourceData, m interface
}

deleteOriginalDisk := proxmox.CustomBool(true)

diskMoveBody := &proxmox.VirtualEnvironmentVMMoveDiskRequestBody{
DeleteOriginalDisk: &deleteOriginalDisk,
Disk: diskInterface,
Expand All @@ -1461,7 +1464,18 @@ func resourceVirtualEnvironmentVMCreateClone(d *schema.ResourceData, m interface
Size: fmt.Sprintf("%dG", diskSize),
}

moveDisk := false

if dataStoreID != "" {
moveDisk = true

if allDiskInfo[diskInterface] != nil {
fileIDParts := strings.Split(allDiskInfo[diskInterface].FileVolume, ":")
moveDisk = dataStoreID != fileIDParts[0]
}
}

if moveDisk {
moveDiskTimeout := d.Get(mkResourceVirtualEnvironmentVMTimeoutMoveDisk).(int)
err = veClient.MoveVMDisk(nodeName, vmID, diskMoveBody, moveDiskTimeout)

Expand All @@ -1470,10 +1484,12 @@ func resourceVirtualEnvironmentVMCreateClone(d *schema.ResourceData, m interface
}
}

err = veClient.ResizeVMDisk(nodeName, vmID, diskResizeBody)
if diskSize > compareNumber {
err = veClient.ResizeVMDisk(nodeName, vmID, diskResizeBody)

if err != nil {
return err
if err != nil {
return err
}
}
}

Expand Down Expand Up @@ -3649,7 +3665,7 @@ func resourceVirtualEnvironmentVMUpdateDiskLocationAndSize(d *schema.ResourceDat
return fmt.Errorf("Deletion of disks not supported. Please delete disk by hand. Old Interface was %s", *oldDisk.Interface)
}

if oldDisk.ID != diskNewEntries[prefix][oldKey].ID {
if *oldDisk.ID != *diskNewEntries[prefix][oldKey].ID {
deleteOriginalDisk := proxmox.CustomBool(true)

diskMoveBodies = append(diskMoveBodies, &proxmox.VirtualEnvironmentVMMoveDiskRequestBody{
Expand Down

0 comments on commit 5871fff

Please sign in to comment.