Skip to content

Commit

Permalink
feat(vm): add configurable timeout for VM create operation (#648)
Browse files Browse the repository at this point in the history
Signed-off-by: Pavel Boldyrev <[email protected]>
  • Loading branch information
bpg authored Oct 25, 2023
1 parent 1d428da commit a30f96c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
5 changes: 3 additions & 2 deletions docs/resources/virtual_environment_vm.md
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ output "ubuntu_vm_public_key" {
- `path_in_datastore` - (Optional) The in-datastore path to the disk image.
***Experimental.***Use to attach another VM's disks,
or (as root only) host's filesystem paths (`datastore_id` empty string).
See "*Example: Attached disks*".
See "*Example: Attached disks*".
- `discard` - (Optional) Whether to pass discard/trim requests to the
underlying storage. Supported values are `on`/`ignore` (defaults
to `ignore`).
Expand Down Expand Up @@ -454,6 +454,8 @@ output "ubuntu_vm_public_key" {
- `template` - (Optional) Whether to create a template (defaults to `false`).
- `timeout_clone` - (Optional) Timeout for cloning a VM in seconds (defaults to
1800).
- `timeout_create` - (Optional) Timeout for creating a VM in seconds (defaults to
1800).
- `timeout_move_disk` - (Optional) Timeout for moving the disk of a VM in
seconds (defaults to 1800).
- `timeout_migrate` - (Optional) Timeout for migrating the VM (defaults to
Expand Down Expand Up @@ -536,7 +538,6 @@ attaching one disk to multiple VM will cause errors or even data corruption.
Do *not* move or resize `data_vm` disks.
(Resource `data_user_vm` should reject attempts to move or resize non-owned disks.)


```terraform
resource "proxmox_virtual_environment_vm" "data_vm" {
node_name = "first-node"
Expand Down
14 changes: 11 additions & 3 deletions proxmoxtf/resource/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ const (
dvResourceVirtualEnvironmentVMTabletDevice = true
dvResourceVirtualEnvironmentVMTemplate = false
dvResourceVirtualEnvironmentVMTimeoutClone = 1800
dvResourceVirtualEnvironmentVMTimeoutCreate = 1800
dvResourceVirtualEnvironmentVMTimeoutMoveDisk = 1800
dvResourceVirtualEnvironmentVMTimeoutMigrate = 1800
dvResourceVirtualEnvironmentVMTimeoutReboot = 1800
Expand Down Expand Up @@ -272,6 +273,7 @@ const (
mkResourceVirtualEnvironmentVMTags = "tags"
mkResourceVirtualEnvironmentVMTemplate = "template"
mkResourceVirtualEnvironmentVMTimeoutClone = "timeout_clone"
mkResourceVirtualEnvironmentVMTimeoutCreate = "timeout_create"
mkResourceVirtualEnvironmentVMTimeoutMoveDisk = "timeout_move_disk"
mkResourceVirtualEnvironmentVMTimeoutMigrate = "timeout_migrate"
mkResourceVirtualEnvironmentVMTimeoutReboot = "timeout_reboot"
Expand All @@ -284,8 +286,6 @@ const (
mkResourceVirtualEnvironmentVMVGAType = "type"
mkResourceVirtualEnvironmentVMVMID = "vm_id"
mkResourceVirtualEnvironmentVMSCSIHardware = "scsi_hardware"

vmCreateTimeoutSeconds = 10
)

// VM returns a resource that manages VMs.
Expand Down Expand Up @@ -1398,6 +1398,12 @@ func VM() *schema.Resource {
Optional: true,
Default: dvResourceVirtualEnvironmentVMTimeoutClone,
},
mkResourceVirtualEnvironmentVMTimeoutCreate: {
Type: schema.TypeInt,
Description: "Create VM timeout",
Optional: true,
Default: dvResourceVirtualEnvironmentVMTimeoutCreate,
},
mkResourceVirtualEnvironmentVMTimeoutMoveDisk: {
Type: schema.TypeInt,
Description: "MoveDisk timeout",
Expand Down Expand Up @@ -2607,7 +2613,9 @@ func vmCreateCustom(ctx context.Context, d *schema.ResourceData, m interface{})
createBody.PoolID = &poolID
}

err = api.Node(nodeName).VM(0).CreateVM(ctx, createBody, vmCreateTimeoutSeconds)
createTimeout := d.Get(mkResourceVirtualEnvironmentVMTimeoutClone).(int)

err = api.Node(nodeName).VM(0).CreateVM(ctx, createBody, createTimeout)
if err != nil {
return diag.FromErr(err)
}
Expand Down

0 comments on commit a30f96c

Please sign in to comment.