mirror of
https://github.com/bpg/terraform-provider-proxmox.git
synced 2025-07-03 20:12:59 +00:00
fix(vm): ignore 599 task status response when waiting for VM start (#1365)
Signed-off-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com>
This commit is contained in:
parent
be94270e1f
commit
5d4193b6be
@ -42,7 +42,7 @@ resource "proxmox_virtual_environment_container" "example_template" {
|
|||||||
node_name = data.proxmox_virtual_environment_nodes.example.names[0]
|
node_name = data.proxmox_virtual_environment_nodes.example.names[0]
|
||||||
|
|
||||||
operating_system {
|
operating_system {
|
||||||
template_file_id = proxmox_virtual_environment_download_file.release_20231211_ubuntu_22_jammy_lxc_img.id
|
template_file_id = proxmox_virtual_environment_download_file.release_20240514_ubuntu_22_jammy_lxc_img.id
|
||||||
type = "ubuntu"
|
type = "ubuntu"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
## Debian and ubuntu image download
|
## Debian and ubuntu image download
|
||||||
|
|
||||||
resource "proxmox_virtual_environment_download_file" "release_20231211_ubuntu_22_jammy_lxc_img" {
|
resource "proxmox_virtual_environment_download_file" "release_20240514_ubuntu_22_jammy_lxc_img" {
|
||||||
content_type = "vztmpl"
|
content_type = "vztmpl"
|
||||||
datastore_id = "local"
|
datastore_id = "local"
|
||||||
node_name = "pve"
|
node_name = "pve"
|
||||||
url = "https://cloud-images.ubuntu.com/releases/22.04/release-20231211/ubuntu-22.04-server-cloudimg-amd64-root.tar.xz"
|
url = var.release_20240416_ubuntu_22_jammy_lxc_img_url
|
||||||
checksum = "c9997dcfea5d826fd04871f960c513665f2e87dd7450bba99f68a97e60e4586e"
|
checksum = var.release_20240416_ubuntu_22_jammy_lxc_img_checksum
|
||||||
checksum_algorithm = "sha256"
|
checksum_algorithm = "sha256"
|
||||||
upload_timeout = 4444
|
upload_timeout = 4444
|
||||||
overwrite_unmanaged = true
|
overwrite_unmanaged = true
|
||||||
@ -16,7 +16,7 @@ resource "proxmox_virtual_environment_download_file" "latest_debian_12_bookworm_
|
|||||||
datastore_id = "local"
|
datastore_id = "local"
|
||||||
file_name = "debian-12-generic-amd64.img"
|
file_name = "debian-12-generic-amd64.img"
|
||||||
node_name = "pve"
|
node_name = "pve"
|
||||||
url = "https://cloud.debian.org/images/cloud/bookworm/latest/debian-12-generic-amd64.qcow2"
|
url = var.latest_debian_12_bookworm_qcow2_img_url
|
||||||
overwrite = true
|
overwrite = true
|
||||||
overwrite_unmanaged = true
|
overwrite_unmanaged = true
|
||||||
}
|
}
|
||||||
|
@ -12,3 +12,21 @@ variable "virtual_environment_ssh_username" {
|
|||||||
type = string
|
type = string
|
||||||
description = "The username for the Proxmox Virtual Environment API"
|
description = "The username for the Proxmox Virtual Environment API"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
variable "latest_debian_12_bookworm_qcow2_img_url" {
|
||||||
|
type = string
|
||||||
|
description = "The URL for the latest Debian 12 Bookworm qcow2 image"
|
||||||
|
default = "https://cloud.debian.org/images/cloud/bookworm/latest/debian-12-generic-amd64.qcow2"
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "release_20240416_ubuntu_22_jammy_lxc_img_url" {
|
||||||
|
type = string
|
||||||
|
description = "The URL for the Ubuntu 22.04 LXC image"
|
||||||
|
default = "https://cloud-images.ubuntu.com/releases/22.04/release-20240416/ubuntu-22.04-server-cloudimg-amd64-root.tar.xz"
|
||||||
|
}
|
||||||
|
|
||||||
|
variable "release_20240416_ubuntu_22_jammy_lxc_img_checksum" {
|
||||||
|
type = string
|
||||||
|
description = "The checksum for the Ubuntu 22.04 LXC image"
|
||||||
|
default = "a362bf415ad2eae4854deda6237894a96178a2edbbd5a1956d6c55c5837a80d3"
|
||||||
|
}
|
||||||
|
@ -89,6 +89,7 @@ func (c *Client) DeleteTask(ctx context.Context, upid string) error {
|
|||||||
|
|
||||||
type taskWaitOptions struct {
|
type taskWaitOptions struct {
|
||||||
ignoreWarnings bool
|
ignoreWarnings bool
|
||||||
|
ignoreStatusCode int
|
||||||
}
|
}
|
||||||
|
|
||||||
// TaskWaitOption is an option for waiting for a task to complete.
|
// TaskWaitOption is an option for waiting for a task to complete.
|
||||||
@ -107,6 +108,19 @@ func (w withIgnoreWarnings) apply(opts *taskWaitOptions) {
|
|||||||
opts.ignoreWarnings = true
|
opts.ignoreWarnings = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type withIgnoreStatus struct {
|
||||||
|
statusCode int
|
||||||
|
}
|
||||||
|
|
||||||
|
// WithIgnoreStatus is an option to ignore particular status code from PVE API when waiting for a task to complete.
|
||||||
|
func WithIgnoreStatus(statusCode int) TaskWaitOption {
|
||||||
|
return withIgnoreStatus{statusCode: statusCode}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w withIgnoreStatus) apply(opts *taskWaitOptions) {
|
||||||
|
opts.ignoreStatusCode = w.statusCode
|
||||||
|
}
|
||||||
|
|
||||||
// WaitForTask waits for a specific task to complete.
|
// WaitForTask waits for a specific task to complete.
|
||||||
func (c *Client) WaitForTask(ctx context.Context, upid string, opts ...TaskWaitOption) error {
|
func (c *Client) WaitForTask(ctx context.Context, upid string, opts ...TaskWaitOption) error {
|
||||||
errStillRunning := errors.New("still running")
|
errStillRunning := errors.New("still running")
|
||||||
@ -140,6 +154,10 @@ func (c *Client) WaitForTask(ctx context.Context, upid string, opts ...TaskWaitO
|
|||||||
// immediately after creation
|
// immediately after creation
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if options.ignoreStatusCode != 0 && target.Code == options.ignoreStatusCode {
|
||||||
|
return true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return errors.Is(err, errStillRunning)
|
return errors.Is(err, errStillRunning)
|
||||||
|
@ -376,7 +376,7 @@ func (c *Client) StartVM(ctx context.Context, timeoutSec int) ([]string, error)
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = c.Tasks().WaitForTask(ctx, *taskID)
|
err = c.Tasks().WaitForTask(ctx, *taskID, tasks.WithIgnoreStatus(599))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log, e := c.Tasks().GetTaskLog(ctx, *taskID)
|
log, e := c.Tasks().GetTaskLog(ctx, *taskID)
|
||||||
if e != nil {
|
if e != nil {
|
||||||
|
@ -552,6 +552,7 @@ github.com/goreleaser/fileglob v1.3.0 h1:/X6J7U8lbDpQtBvGcwwPS6OpzkNVlVEsFUVRx9+
|
|||||||
github.com/goreleaser/fileglob v1.3.0/go.mod h1:Jx6BoXv3mbYkEzwm9THo7xbr5egkAraxkGorbJb4RxU=
|
github.com/goreleaser/fileglob v1.3.0/go.mod h1:Jx6BoXv3mbYkEzwm9THo7xbr5egkAraxkGorbJb4RxU=
|
||||||
github.com/goreleaser/goreleaser v1.26.2 h1:1iY1HaXtRiMTrwy6KE1sNjkRjsjMi+9l0k6WUX8GpWw=
|
github.com/goreleaser/goreleaser v1.26.2 h1:1iY1HaXtRiMTrwy6KE1sNjkRjsjMi+9l0k6WUX8GpWw=
|
||||||
github.com/goreleaser/goreleaser v1.26.2/go.mod h1:mHi6zr6fuuOh5eHdWWgyo/N8BWED5WEVtb/4GETc9jQ=
|
github.com/goreleaser/goreleaser v1.26.2/go.mod h1:mHi6zr6fuuOh5eHdWWgyo/N8BWED5WEVtb/4GETc9jQ=
|
||||||
|
github.com/goreleaser/goreleaser/v2 v2.0.0/go.mod h1:eit+2+u8uJLgBtuEMITPaQHwO55amhR089eFkbWi3s0=
|
||||||
github.com/goreleaser/nfpm/v2 v2.37.1 h1:RUmeEt8OlEVeSzKRrO5Vl5qVWCtUwx4j9uivGuRo5fw=
|
github.com/goreleaser/nfpm/v2 v2.37.1 h1:RUmeEt8OlEVeSzKRrO5Vl5qVWCtUwx4j9uivGuRo5fw=
|
||||||
github.com/goreleaser/nfpm/v2 v2.37.1/go.mod h1:q8+sZXFqn106/eGw+9V+I8+izFxZ/sJjrhwmEUxXhUg=
|
github.com/goreleaser/nfpm/v2 v2.37.1/go.mod h1:q8+sZXFqn106/eGw+9V+I8+izFxZ/sJjrhwmEUxXhUg=
|
||||||
github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY=
|
github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY=
|
||||||
|
Loading…
Reference in New Issue
Block a user