Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix: reboot VM gracefully #861

Merged
merged 2 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ module github.com/Telmate/terraform-provider-proxmox/v2

go 1.19

replace github.com/Telmate/proxmox-api-go v0.0.0-20230616173359-03f4e428f6c6 => github.com/lucian-tx/proxmox-api-go v0.0.0-20231107082852-a957835da721

require (
github.com/Telmate/proxmox-api-go v0.0.0-20230411210559-73bbbf4297e1
github.com/google/uuid v1.3.1
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
github.com/lucian-tx/proxmox-api-go v0.0.0-20231107082852-a957835da721 h1:IF5IveFrnRn5GFdglJ88fgiDQVKN94ebET9ZPCtLYMo=
github.com/lucian-tx/proxmox-api-go v0.0.0-20231107082852-a957835da721/go.mod h1:HKwnwBcgJxT+UjTUyRP7+aDxXSgu0kLWvlrRhd4i1YU=
github.com/matryer/is v1.2.0/go.mod h1:2fLPjFQM9rhQ15aVEtbuwhJinnOqrmgXPNdZsdwlWXA=
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
Expand Down
23 changes: 17 additions & 6 deletions proxmox/resource_vm_qemu.go
Original file line number Diff line number Diff line change
Expand Up @@ -1404,7 +1404,9 @@ func resourceVmQemuUpdate(ctx context.Context, d *schema.ResourceData, meta inte
// give sometime to proxmox to catchup
time.Sleep(time.Duration(d.Get("additional_wait").(int)) * time.Second)

prepareDiskSize(client, vmr, qemuDisks, d)
if err := prepareDiskSize(client, vmr, qemuDisks, d); err != nil {
return diag.FromErr(err)
}

// give sometime to proxmox to catchup
time.Sleep(time.Duration(d.Get("additional_wait").(int)) * time.Second)
Expand Down Expand Up @@ -1573,13 +1575,22 @@ func resourceVmQemuUpdate(ctx context.Context, d *schema.ResourceData, meta inte
}
} else if err == nil && vmState["status"] != "stopped" && d.Get("reboot_required").(bool) {
if d.Get("automatic_reboot").(bool) {
log.Print("[DEBUG][QemuVmUpdate] shutting down VM for required reboot")
_, err = client.ShutdownVm(vmr)
log.Print("[DEBUG][QemuVmUpdate] rebooting the VM to match the configuration changes")
_, err = client.RebootVm(vmr)
// note: the default timeout is 3 min, configurable per VM: Options/Start-Shutdown Order/Shutdown timeout
if err != nil {
log.Print("[DEBUG][QemuVmUpdate] shutdown failed, stopping VM forcefully")
_, err = client.StopVm(vmr)
if err != nil {
log.Print("[DEBUG][QemuVmUpdate] reboot failed, stopping VM forcefully")

if _, err := client.StopVm(vmr); err != nil {
return diag.FromErr(err)
}

// give sometime to proxmox to catchup
dur := time.Duration(d.Get("additional_wait").(int)) * time.Second
log.Printf("[DEBUG][QemuVmUpdate] waiting for (%v) before starting the VM again", dur)
time.Sleep(dur)

if _, err := client.StartVm(vmr); err != nil {
return diag.FromErr(err)
}
}
Expand Down
Loading