From d36cf4eab81955184c926c86ce692bcf6c01b840 Mon Sep 17 00:00:00 2001 From: Simon Caron <8635747+simoncaron@users.noreply.github.com> Date: Sat, 7 Oct 2023 20:08:09 -0400 Subject: [PATCH] feat(lxc): add support for the `start_on_boot` option (#605) * feat(lxc): add support for the `start_on_boot` option Signed-off-by: Simon Caron * Move code next to started blocks + update default value Signed-off-by: Simon Caron --------- Signed-off-by: Simon Caron Co-authored-by: Simon Caron --- docs/resources/virtual_environment_container.md | 1 + proxmoxtf/resource/container.go | 13 ++++++++++++- proxmoxtf/resource/container_test.go | 2 ++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/docs/resources/virtual_environment_container.md b/docs/resources/virtual_environment_container.md index b89330bdb..841a9287 100644 --- a/docs/resources/virtual_environment_container.md +++ b/docs/resources/virtual_environment_container.md @@ -188,6 +188,7 @@ output "ubuntu_container_public_key" { - `unmanaged` - Unmanaged. - `pool_id` - (Optional) The identifier for a pool to assign the container to. - `started` - (Optional) Whether to start the container (defaults to `true`). +- `start_on_boot` - (Optional) Automatically start container when the host system boots (defaults to `true`). - `tags` - (Optional) A list of tags the container tags. This is only meta information (defaults to `[]`). Note: Proxmox always sorts the container tags. If the list in template is not sorted, then Proxmox will always report a diff --git a/proxmoxtf/resource/container.go b/proxmoxtf/resource/container.go index 4f38b439..655b5988 100644 --- a/proxmoxtf/resource/container.go +++ b/proxmoxtf/resource/container.go @@ -65,6 +65,7 @@ const ( dvResourceVirtualEnvironmentContainerOperatingSystemType = "unmanaged" dvResourceVirtualEnvironmentContainerPoolID = "" dvResourceVirtualEnvironmentContainerStarted = true + dvResourceVirtualEnvironmentContainerStartOnBoot = true dvResourceVirtualEnvironmentContainerTemplate = false dvResourceVirtualEnvironmentContainerUnprivileged = false dvResourceVirtualEnvironmentContainerVMID = -1 @@ -135,6 +136,7 @@ const ( mkResourceVirtualEnvironmentContainerOperatingSystemType = "type" mkResourceVirtualEnvironmentContainerPoolID = "pool_id" mkResourceVirtualEnvironmentContainerStarted = "started" + mkResourceVirtualEnvironmentContainerStartOnBoot = "start_on_boot" mkResourceVirtualEnvironmentContainerTags = "tags" mkResourceVirtualEnvironmentContainerTemplate = "template" mkResourceVirtualEnvironmentContainerUnprivileged = "unprivileged" @@ -717,6 +719,13 @@ func Container() *schema.Resource { return d.Get(mkResourceVirtualEnvironmentContainerTemplate).(bool) }, }, + mkResourceVirtualEnvironmentContainerStartOnBoot: { + Type: schema.TypeBool, + Description: "Automatically start container when the host system boots.", + Optional: true, + ForceNew: false, + Default: dvResourceVirtualEnvironmentContainerStartOnBoot, + }, mkResourceVirtualEnvironmentContainerTags: { Type: schema.TypeList, Description: "Tags of the container. This is only meta information.", @@ -1448,6 +1457,7 @@ func containerCreateCustom(ctx context.Context, d *schema.ResourceData, m interf poolID := d.Get(mkResourceVirtualEnvironmentContainerPoolID).(string) started := types.CustomBool(d.Get(mkResourceVirtualEnvironmentContainerStarted).(bool)) + startOnBoot := types.CustomBool(d.Get(mkResourceVirtualEnvironmentContainerStartOnBoot).(bool)) tags := d.Get(mkResourceVirtualEnvironmentContainerTags).([]interface{}) template := types.CustomBool(d.Get(mkResourceVirtualEnvironmentContainerTemplate).(bool)) unprivileged := types.CustomBool(d.Get(mkResourceVirtualEnvironmentContainerUnprivileged).(bool)) @@ -1477,7 +1487,8 @@ func containerCreateCustom(ctx context.Context, d *schema.ResourceData, m interf OSTemplateFileVolume: &operatingSystemTemplateFileID, OSType: &operatingSystemType, RootFS: rootFS, - StartOnBoot: &started, + Start: &started, + StartOnBoot: &startOnBoot, Swap: &memorySwap, Template: &template, TTY: &consoleTTYCount, diff --git a/proxmoxtf/resource/container_test.go b/proxmoxtf/resource/container_test.go index 101127d2..e322fd54 100644 --- a/proxmoxtf/resource/container_test.go +++ b/proxmoxtf/resource/container_test.go @@ -47,6 +47,7 @@ func TestContainerSchema(t *testing.T) { mkResourceVirtualEnvironmentContainerTags, mkResourceVirtualEnvironmentContainerTemplate, mkResourceVirtualEnvironmentContainerUnprivileged, + mkResourceVirtualEnvironmentContainerStartOnBoot, mkResourceVirtualEnvironmentContainerFeatures, mkResourceVirtualEnvironmentContainerVMID, }) @@ -64,6 +65,7 @@ func TestContainerSchema(t *testing.T) { mkResourceVirtualEnvironmentContainerTags: schema.TypeList, mkResourceVirtualEnvironmentContainerTemplate: schema.TypeBool, mkResourceVirtualEnvironmentContainerUnprivileged: schema.TypeBool, + mkResourceVirtualEnvironmentContainerStartOnBoot: schema.TypeBool, mkResourceVirtualEnvironmentContainerFeatures: schema.TypeList, mkResourceVirtualEnvironmentContainerVMID: schema.TypeInt, })