Skip to content

Commit

Permalink
fix(vm): do not reboot at disk resize (#1580)
Browse files Browse the repository at this point in the history
Signed-off-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com>
  • Loading branch information
bpg authored Oct 8, 2024
1 parent 51d0338 commit 90c50fc
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
13 changes: 13 additions & 0 deletions proxmox/helpers/ptr/ptr.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,16 @@ func Or[T any](p *T, or T) T {

return or
}

// Eq compares two pointers and returns true if they are equal.
func Eq[T comparable](a, b *T) bool {
if a == nil && b == nil {
return true
}

if a == nil || b == nil {
return false
}

return *a == *b
}
3 changes: 2 additions & 1 deletion proxmoxtf/resource/vm/disk/disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"

"github.com/bpg/terraform-provider-proxmox/proxmox"
"github.com/bpg/terraform-provider-proxmox/proxmox/helpers/ptr"
"github.com/bpg/terraform-provider-proxmox/proxmox/nodes/vms"
"github.com/bpg/terraform-provider-proxmox/proxmox/ssh"
"github.com/bpg/terraform-provider-proxmox/proxmox/types"
Expand Down Expand Up @@ -602,7 +603,7 @@ func Update(
continue
}

if tmp.AIO != disk.AIO {
if !ptr.Eq(tmp.AIO, disk.AIO) {
rebootRequired = true
tmp.AIO = disk.AIO
}
Expand Down
9 changes: 8 additions & 1 deletion proxmoxtf/resource/vm/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -5523,12 +5523,19 @@ func vmUpdateDiskLocationAndSize(
)
} else {
return diag.Errorf(
"Cannot resize %s:%s in VM %d configuration, it is not owned by this VM!",
"Cannot resize %s:%s in VM %d, it is not owned by this VM!",
*oldDisk.DatastoreID,
*oldDisk.PathInDatastore(),
vmID,
)
}
} else {
return diag.Errorf(
"Cannot shrink %s:%s in VM %d, it is not supported!",
*oldDisk.DatastoreID,
*oldDisk.PathInDatastore(),
vmID,
)
}
}

Expand Down

0 comments on commit 90c50fc

Please sign in to comment.