From 94f2ba5456f1c892251d2ce4390e7fb1d97cd224 Mon Sep 17 00:00:00 2001 From: Josh Williams Date: Wed, 6 Dec 2023 05:30:22 -0600 Subject: [PATCH] Feat: Gracefully shutdown VM on deletion. (#872) * Gracefully shutdown VM on deletion. This allows things like DHCP reservations to be cleaned up. * Attempt graceful shutdown only if guest agent is enabled. --- proxmox/resource_vm_qemu.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/proxmox/resource_vm_qemu.go b/proxmox/resource_vm_qemu.go index 2763a932..0381d906 100755 --- a/proxmox/resource_vm_qemu.go +++ b/proxmox/resource_vm_qemu.go @@ -1931,7 +1931,12 @@ func resourceVmQemuDelete(ctx context.Context, d *schema.ResourceData, meta inte return diag.FromErr(err) } if vmState["status"] != "stopped" { - _, err := client.StopVm(vmr) + var err error + if d.Get("agent") == 1 { + _, err = client.ShutdownVm(vmr) + } else { + _, err = client.StopVm(vmr) + } if err != nil { return diag.FromErr(err) }