Skip to content

Commit

Permalink
Bugfix: reboot VM gracefully
Browse files Browse the repository at this point in the history
  • Loading branch information
lucian-tx committed Nov 7, 2023
1 parent 4c0c8fc commit efb4c5c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ module github.com/Telmate/terraform-provider-proxmox

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/Telmate/proxmox-api-go v0.0.0-20230616173359-03f4e428f6c6
github.com/google/uuid v1.3.0
github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320
github.com/hashicorp/terraform-plugin-sdk/v2 v2.26.1
Expand Down
6 changes: 3 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ github.com/Microsoft/go-winio v0.4.16 h1:FtSW/jqD+l4ba5iPBj9CODVtgfYAD8w2wS923g/
github.com/Microsoft/go-winio v0.4.16/go.mod h1:XB6nPKklQyQ7GC9LdcBEcBl8PF76WugXOPRXwdLnMv0=
github.com/ProtonMail/go-crypto v0.0.0-20210428141323-04723f9f07d7 h1:YoJbenK9C67SkzkDfmQuVln04ygHj3vjZfd9FL+GmQQ=
github.com/ProtonMail/go-crypto v0.0.0-20210428141323-04723f9f07d7/go.mod h1:z4/9nQmJSSwwds7ejkxaJwO37dru3geImFUdJlaLzQo=
github.com/Telmate/proxmox-api-go v0.0.0-20230411210559-73bbbf4297e1 h1:OwwFd8l+Zosmn1Auh0RTyVcrAMAvx5wrIhY/CpQ2PBg=
github.com/Telmate/proxmox-api-go v0.0.0-20230411210559-73bbbf4297e1/go.mod h1:zQ/B1nkMv6ueUlAEr0D/x5eaFe3rHSScuTc08dcvvPI=
github.com/acomagu/bufpipe v1.0.3 h1:fxAGrHZTgQ9w5QqVItgzwj235/uYZYgbXitB+dLupOk=
github.com/acomagu/bufpipe v1.0.3/go.mod h1:mxdxdup/WdsKVreO5GpW4+M/1CE2sMG4jeGJ2sYmHc4=
github.com/agext/levenshtein v1.2.3 h1:YB2fHEn0UJagG8T1rrWknE3ZQzWM06O8AMAatNn7lmo=
Expand Down Expand Up @@ -122,6 +120,8 @@ github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
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=
Expand Down Expand Up @@ -173,7 +173,7 @@ github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals=
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
github.com/vmihailenco/msgpack v3.3.3+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk=
github.com/vmihailenco/msgpack v4.0.4+incompatible h1:dSLoQfGFAo3F6OoNhwUmLwVgaUXK79GlxNBwueZn0xI=
github.com/vmihailenco/msgpack v4.0.4+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk=
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 @@ -1326,7 +1326,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 @@ -1495,13 +1497,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

0 comments on commit efb4c5c

Please sign in to comment.