Skip to content

Commit

Permalink
Feat: Gracefully shutdown VM on deletion. (#872)
Browse files Browse the repository at this point in the history
* Gracefully shutdown VM on deletion.

This allows things like DHCP reservations to be cleaned up.

* Attempt graceful shutdown only if guest agent is enabled.
  • Loading branch information
t3hpr1m3 authored Dec 6, 2023
1 parent a1ec3aa commit 94f2ba5
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion proxmox/resource_vm_qemu.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit 94f2ba5

Please sign in to comment.