From 90c50fcb471c66448652f089039ed8cef9a3bbc7 Mon Sep 17 00:00:00 2001 From: Pavel Boldyrev <627562+bpg@users.noreply.github.com> Date: Mon, 7 Oct 2024 20:47:39 -0400 Subject: [PATCH] fix(vm): do not reboot at disk resize (#1580) Signed-off-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com> --- proxmox/helpers/ptr/ptr.go | 13 +++++++++++++ proxmoxtf/resource/vm/disk/disk.go | 3 ++- proxmoxtf/resource/vm/vm.go | 9 ++++++++- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/proxmox/helpers/ptr/ptr.go b/proxmox/helpers/ptr/ptr.go index e533d4dd..a47264e0 100644 --- a/proxmox/helpers/ptr/ptr.go +++ b/proxmox/helpers/ptr/ptr.go @@ -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 +} diff --git a/proxmoxtf/resource/vm/disk/disk.go b/proxmoxtf/resource/vm/disk/disk.go index 13d494ac..b35d4cb1 100644 --- a/proxmoxtf/resource/vm/disk/disk.go +++ b/proxmoxtf/resource/vm/disk/disk.go @@ -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" @@ -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 } diff --git a/proxmoxtf/resource/vm/vm.go b/proxmoxtf/resource/vm/vm.go index 8dbf1131..252d1bd6 100644 --- a/proxmoxtf/resource/vm/vm.go +++ b/proxmoxtf/resource/vm/vm.go @@ -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, + ) } }