mirror of
https://github.com/bpg/terraform-provider-proxmox.git
synced 2025-06-30 02:31:10 +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.
|
||||
- `template` - (Optional) Whether to create a template (defaults to `false`).
|
||||
- `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
|
||||
the host (defaults to `false`).
|
||||
- `vm_id` - (Optional) The container identifier
|
||||
|
@ -76,6 +76,7 @@ const (
|
||||
dvStartOnBoot = true
|
||||
dvTemplate = false
|
||||
dvTimeoutCreate = 1800
|
||||
dvTimeoutStart = 300
|
||||
dvUnprivileged = false
|
||||
dvVMID = -1
|
||||
|
||||
@ -156,6 +157,7 @@ const (
|
||||
mkTags = "tags"
|
||||
mkTemplate = "template"
|
||||
mkTimeoutCreate = "timeout_create"
|
||||
mkTimeoutStart = "timeout_start"
|
||||
mkUnprivileged = "unprivileged"
|
||||
mkVMID = "vm_id"
|
||||
)
|
||||
@ -842,6 +844,12 @@ func Container() *schema.Resource {
|
||||
Optional: true,
|
||||
Default: dvTimeoutCreate,
|
||||
},
|
||||
mkTimeoutStart: {
|
||||
Type: schema.TypeInt,
|
||||
Description: "Start container timeout",
|
||||
Optional: true,
|
||||
Default: dvTimeoutStart,
|
||||
},
|
||||
mkUnprivileged: {
|
||||
Type: schema.TypeBool,
|
||||
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))
|
||||
unprivileged := types.CustomBool(d.Get(mkUnprivileged).(bool))
|
||||
vmID := d.Get(mkVMID).(int)
|
||||
createTimeout := d.Get(mkTimeoutCreate).(int)
|
||||
|
||||
if vmID == -1 {
|
||||
vmIDNew, e := api.Cluster().GetVMID(ctx)
|
||||
@ -1689,7 +1698,7 @@ func containerCreateCustom(ctx context.Context, d *schema.ResourceData, m interf
|
||||
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 {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
@ -1729,10 +1738,10 @@ func containerCreateStart(ctx context.Context, d *schema.ResourceData, m interfa
|
||||
|
||||
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.
|
||||
err = containerAPI.StartContainer(ctx, createTimeout)
|
||||
err = containerAPI.StartContainer(ctx, startTimeout)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user