From 32bdc94167253b7b3ec6eaecbccc2d2cc0104b61 Mon Sep 17 00:00:00 2001 From: Pavel Boldyrev <627562+bpg@users.noreply.github.com> Date: Sun, 8 Oct 2023 20:35:34 -0400 Subject: [PATCH] fix(lxc): create container when authenticated with API token (#610) And also fix container startup behaviour: "error starting container ... - already running" Signed-off-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com> --- proxmoxtf/resource/container.go | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/proxmoxtf/resource/container.go b/proxmoxtf/resource/container.go index 655b5988..1bb570b0 100644 --- a/proxmoxtf/resource/container.go +++ b/proxmoxtf/resource/container.go @@ -1226,10 +1226,18 @@ func containerCreateCustom(ctx context.Context, d *schema.ResourceData, m interf keyctl := types.CustomBool(featuresBlock[mkResourceVirtualEnvironmentContainerFeaturesKeyControl].(bool)) fuse := types.CustomBool(featuresBlock[mkResourceVirtualEnvironmentContainerFeaturesFUSE].(bool)) - features := containers.CustomFeatures{ - Nesting: &nesting, - KeyControl: &keyctl, - FUSE: &fuse, + features := containers.CustomFeatures{} + + if nesting { + features.Nesting = &nesting + } + + if keyctl { + features.KeyControl = &keyctl + } + + if fuse { + features.FUSE = &fuse } initialization := d.Get(mkResourceVirtualEnvironmentContainerInitialization).([]interface{}) @@ -1567,12 +1575,7 @@ func containerCreateStart(ctx context.Context, d *schema.ResourceData, m interfa containerAPI := api.Node(nodeName).Container(vmID) - // Start the container and wait for it to reach a running state before continuing. - err = containerAPI.StartContainer(ctx, 60) - if err != nil { - return diag.FromErr(err) - } - + // A container was started by the create operation, so wait for it to be running. err = containerAPI.WaitForContainerState(ctx, "running", 120, 5) if err != nil { return diag.FromErr(err)