mirror of
https://github.com/bpg/terraform-provider-proxmox.git
synced 2025-06-30 10:33:46 +00:00
fix(lxc): improve configurable timeouts for containers operations (#1161)
feat(lxc): Improve configurable timeouts for containers operations Fix timeouts on CT creation (related to #1160) Add configurable timeout for CT start Signed-off-by: Soubinan <contact@soubinan.tk> Co-authored-by: Soubinan <contact@soubinan.tk>
This commit is contained in:
parent
3020e56bed
commit
c45e3367e7
@ -215,6 +215,7 @@ output "ubuntu_container_public_key" {
|
|||||||
meta-argument to ignore changes to this attribute.
|
meta-argument to ignore changes to this attribute.
|
||||||
- `template` - (Optional) Whether to create a template (defaults to `false`).
|
- `template` - (Optional) Whether to create a template (defaults to `false`).
|
||||||
- `timeout_create` - (Optional) Timeout for creating a container in seconds (defaults to 1800).
|
- `timeout_create` - (Optional) Timeout for creating a container in seconds (defaults to 1800).
|
||||||
|
- `timeout_start` - (Optional) Timeout for starting a container in seconds (defaults to 300).
|
||||||
- `unprivileged` - (Optional) Whether the container runs as unprivileged on
|
- `unprivileged` - (Optional) Whether the container runs as unprivileged on
|
||||||
the host (defaults to `false`).
|
the host (defaults to `false`).
|
||||||
- `vm_id` - (Optional) The container identifier
|
- `vm_id` - (Optional) The container identifier
|
||||||
|
@ -76,6 +76,7 @@ const (
|
|||||||
dvStartOnBoot = true
|
dvStartOnBoot = true
|
||||||
dvTemplate = false
|
dvTemplate = false
|
||||||
dvTimeoutCreate = 1800
|
dvTimeoutCreate = 1800
|
||||||
|
dvTimeoutStart = 300
|
||||||
dvUnprivileged = false
|
dvUnprivileged = false
|
||||||
dvVMID = -1
|
dvVMID = -1
|
||||||
|
|
||||||
@ -156,6 +157,7 @@ const (
|
|||||||
mkTags = "tags"
|
mkTags = "tags"
|
||||||
mkTemplate = "template"
|
mkTemplate = "template"
|
||||||
mkTimeoutCreate = "timeout_create"
|
mkTimeoutCreate = "timeout_create"
|
||||||
|
mkTimeoutStart = "timeout_start"
|
||||||
mkUnprivileged = "unprivileged"
|
mkUnprivileged = "unprivileged"
|
||||||
mkVMID = "vm_id"
|
mkVMID = "vm_id"
|
||||||
)
|
)
|
||||||
@ -842,6 +844,12 @@ func Container() *schema.Resource {
|
|||||||
Optional: true,
|
Optional: true,
|
||||||
Default: dvTimeoutCreate,
|
Default: dvTimeoutCreate,
|
||||||
},
|
},
|
||||||
|
mkTimeoutStart: {
|
||||||
|
Type: schema.TypeInt,
|
||||||
|
Description: "Start container timeout",
|
||||||
|
Optional: true,
|
||||||
|
Default: dvTimeoutStart,
|
||||||
|
},
|
||||||
mkUnprivileged: {
|
mkUnprivileged: {
|
||||||
Type: schema.TypeBool,
|
Type: schema.TypeBool,
|
||||||
Description: "Whether the container runs as unprivileged on the host",
|
Description: "Whether the container runs as unprivileged on the host",
|
||||||
@ -1617,6 +1625,7 @@ func containerCreateCustom(ctx context.Context, d *schema.ResourceData, m interf
|
|||||||
template := types.CustomBool(d.Get(mkTemplate).(bool))
|
template := types.CustomBool(d.Get(mkTemplate).(bool))
|
||||||
unprivileged := types.CustomBool(d.Get(mkUnprivileged).(bool))
|
unprivileged := types.CustomBool(d.Get(mkUnprivileged).(bool))
|
||||||
vmID := d.Get(mkVMID).(int)
|
vmID := d.Get(mkVMID).(int)
|
||||||
|
createTimeout := d.Get(mkTimeoutCreate).(int)
|
||||||
|
|
||||||
if vmID == -1 {
|
if vmID == -1 {
|
||||||
vmIDNew, e := api.Cluster().GetVMID(ctx)
|
vmIDNew, e := api.Cluster().GetVMID(ctx)
|
||||||
@ -1689,7 +1698,7 @@ func containerCreateCustom(ctx context.Context, d *schema.ResourceData, m interf
|
|||||||
createBody.Tags = &tagsString
|
createBody.Tags = &tagsString
|
||||||
}
|
}
|
||||||
|
|
||||||
err = api.Node(nodeName).Container(0).CreateContainer(ctx, &createBody, 60)
|
err = api.Node(nodeName).Container(0).CreateContainer(ctx, &createBody, createTimeout)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
@ -1729,10 +1738,10 @@ func containerCreateStart(ctx context.Context, d *schema.ResourceData, m interfa
|
|||||||
|
|
||||||
containerAPI := api.Node(nodeName).Container(vmID)
|
containerAPI := api.Node(nodeName).Container(vmID)
|
||||||
|
|
||||||
createTimeout := d.Get(mkTimeoutCreate).(int)
|
startTimeout := d.Get(mkTimeoutStart).(int)
|
||||||
|
|
||||||
// Start the container and wait for it to reach a running state before continuing.
|
// Start the container and wait for it to reach a running state before continuing.
|
||||||
err = containerAPI.StartContainer(ctx, createTimeout)
|
err = containerAPI.StartContainer(ctx, startTimeout)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user