From aa9cdba0bf6dfd817c57384f6f688009a9e82635 Mon Sep 17 00:00:00 2001 From: CaptaiNiveau Date: Mon, 31 Mar 2025 02:20:30 +0200 Subject: [PATCH] fix(lxc): multiple issues during container import (#1867) * fix(container): Added `Unprivileged` to `containerRead` on import Signed-off-by: CaptaiNiveau * fix(container): Changed default value of device passthrough mode to 0660 Signed-off-by: CaptaiNiveau * chore(lxc): add default device passthrough mode to the schema, update acc tests Signed-off-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com> --------- Signed-off-by: CaptaiNiveau Signed-off-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com> Co-authored-by: CaptaiNiveau Co-authored-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com> --- fwprovider/test/resource_container_test.go | 8 +++++--- proxmoxtf/resource/container/container.go | 19 ++++++++++++++++++- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/fwprovider/test/resource_container_test.go b/fwprovider/test/resource_container_test.go index f7bde74d..f54e71bf 100644 --- a/fwprovider/test/resource_container_test.go +++ b/fwprovider/test/resource_container_test.go @@ -104,9 +104,11 @@ func TestAccResourceContainer(t *testing.T) { }`, WithRootUser()), Check: resource.ComposeTestCheckFunc( ResourceAttributes(accTestContainerName, map[string]string{ - "description": "my\ndescription\nvalue\n", - "device_passthrough.#": "1", - "initialization.0.dns.#": "0", + "unprivileged": "true", + "description": "my\ndescription\nvalue\n", + "device_passthrough.#": "1", + "device_passthrough.0.mode": "0660", + "initialization.0.dns.#": "0", }), func(*terraform.State) error { ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) diff --git a/proxmoxtf/resource/container/container.go b/proxmoxtf/resource/container/container.go index b88cc5c6..3ea7949a 100644 --- a/proxmoxtf/resource/container/container.go +++ b/proxmoxtf/resource/container/container.go @@ -50,6 +50,7 @@ const ( dvCPUCores = 1 dvCPUUnits = 1024 dvDescription = "" + dvDevicePassthroughMode = "0660" dvDiskDatastoreID = "local" dvDiskSize = 4 dvFeaturesNesting = false @@ -710,6 +711,7 @@ func Container() *schema.Resource { Type: schema.TypeString, Description: "Access mode to be set on the device node (e.g. 0666)", Optional: true, + Default: dvDevicePassthroughMode, ValidateDiagFunc: validation.ToDiagFunc(validation.StringMatch( regexp.MustCompile(`0[0-7]{3}`), "Octal access mode", )), @@ -2376,7 +2378,7 @@ func containerRead(ctx context.Context, d *schema.ResourceData, m interface{}) d if dp.Mode != nil { devicePassthrough[mkDevicePassthroughMode] = *dp.Mode } else { - devicePassthrough[mkDevicePassthroughMode] = "" + devicePassthrough[mkDevicePassthroughMode] = dvDevicePassthroughMode } devicePassthrough[mkDevicePassthroughPath] = dp.Path @@ -2744,6 +2746,21 @@ func containerRead(ctx context.Context, d *schema.ResourceData, m interface{}) d diags = append(diags, diag.FromErr(err)...) } + currentUnprivileged := types.CustomBool(d.Get(mkUnprivileged).(bool)) + + if len(clone) == 0 || currentUnprivileged { + if containerConfig.Unprivileged != nil { + e = d.Set( + mkUnprivileged, + bool(*containerConfig.Unprivileged), + ) + } else { + e = d.Set(mkUnprivileged, false) + } + + diags = append(diags, diag.FromErr(e)...) + } + currentProtection := types.CustomBool(d.Get(mkProtection).(bool)) if len(clone) == 0 || currentProtection {