mirror of
https://github.com/bpg/terraform-provider-proxmox.git
synced 2025-08-22 19:38:35 +00:00
fix(lxc): multiple issues during container import (#1867)
* fix(container): Added `Unprivileged` to `containerRead` on import Signed-off-by: CaptaiNiveau <c.straten@proton.me> * fix(container): Changed default value of device passthrough mode to 0660 Signed-off-by: CaptaiNiveau <c.straten@proton.me> * 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 <c.straten@proton.me> Signed-off-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com> Co-authored-by: CaptaiNiveau <c.straten@proton.me> Co-authored-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com>
This commit is contained in:
parent
2a356014a1
commit
aa9cdba0bf
@ -104,9 +104,11 @@ func TestAccResourceContainer(t *testing.T) {
|
|||||||
}`, WithRootUser()),
|
}`, WithRootUser()),
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
ResourceAttributes(accTestContainerName, map[string]string{
|
ResourceAttributes(accTestContainerName, map[string]string{
|
||||||
"description": "my\ndescription\nvalue\n",
|
"unprivileged": "true",
|
||||||
"device_passthrough.#": "1",
|
"description": "my\ndescription\nvalue\n",
|
||||||
"initialization.0.dns.#": "0",
|
"device_passthrough.#": "1",
|
||||||
|
"device_passthrough.0.mode": "0660",
|
||||||
|
"initialization.0.dns.#": "0",
|
||||||
}),
|
}),
|
||||||
func(*terraform.State) error {
|
func(*terraform.State) error {
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||||
|
@ -50,6 +50,7 @@ const (
|
|||||||
dvCPUCores = 1
|
dvCPUCores = 1
|
||||||
dvCPUUnits = 1024
|
dvCPUUnits = 1024
|
||||||
dvDescription = ""
|
dvDescription = ""
|
||||||
|
dvDevicePassthroughMode = "0660"
|
||||||
dvDiskDatastoreID = "local"
|
dvDiskDatastoreID = "local"
|
||||||
dvDiskSize = 4
|
dvDiskSize = 4
|
||||||
dvFeaturesNesting = false
|
dvFeaturesNesting = false
|
||||||
@ -710,6 +711,7 @@ func Container() *schema.Resource {
|
|||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Description: "Access mode to be set on the device node (e.g. 0666)",
|
Description: "Access mode to be set on the device node (e.g. 0666)",
|
||||||
Optional: true,
|
Optional: true,
|
||||||
|
Default: dvDevicePassthroughMode,
|
||||||
ValidateDiagFunc: validation.ToDiagFunc(validation.StringMatch(
|
ValidateDiagFunc: validation.ToDiagFunc(validation.StringMatch(
|
||||||
regexp.MustCompile(`0[0-7]{3}`), "Octal access mode",
|
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 {
|
if dp.Mode != nil {
|
||||||
devicePassthrough[mkDevicePassthroughMode] = *dp.Mode
|
devicePassthrough[mkDevicePassthroughMode] = *dp.Mode
|
||||||
} else {
|
} else {
|
||||||
devicePassthrough[mkDevicePassthroughMode] = ""
|
devicePassthrough[mkDevicePassthroughMode] = dvDevicePassthroughMode
|
||||||
}
|
}
|
||||||
|
|
||||||
devicePassthrough[mkDevicePassthroughPath] = dp.Path
|
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)...)
|
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))
|
currentProtection := types.CustomBool(d.Get(mkProtection).(bool))
|
||||||
|
|
||||||
if len(clone) == 0 || currentProtection {
|
if len(clone) == 0 || currentProtection {
|
||||||
|
Loading…
Reference in New Issue
Block a user