From c39a061825feb91f1bd29c57eb99e565346db796 Mon Sep 17 00:00:00 2001 From: Pavel Boldyrev <627562+bpg@users.noreply.github.com> Date: Sun, 10 Aug 2025 14:13:26 -0400 Subject: [PATCH] fix rootfs unmarshalling from API response Signed-off-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com> --- fwprovider/test/resource_container_test.go | 51 +++++++++++++++++++- proxmox/nodes/containers/containers_types.go | 4 +- proxmoxtf/resource/container/container.go | 6 +-- 3 files changed, 55 insertions(+), 6 deletions(-) diff --git a/fwprovider/test/resource_container_test.go b/fwprovider/test/resource_container_test.go index 6967f877..9d251fb3 100644 --- a/fwprovider/test/resource_container_test.go +++ b/fwprovider/test/resource_container_test.go @@ -71,7 +71,6 @@ func TestAccResourceContainer(t *testing.T) { unprivileged = true disk { datastore_id = "local-lvm" - mount_options = ["discard"] size = 4 } mount_point { @@ -144,6 +143,7 @@ func TestAccResourceContainer(t *testing.T) { disk { datastore_id = "local-lvm" size = 4 + mount_options = ["discard"] } mount_point { volume = "local-lvm" @@ -180,6 +180,55 @@ func TestAccResourceContainer(t *testing.T) { "description": "my\ndescription\nvalue\n", "device_passthrough.#": "1", "initialization.0.dns.#": "0", + "disk.0.mount_options.#": "1", + }), + ), + }, + { + // remove disk options + Config: te.RenderConfig(` + resource "proxmox_virtual_environment_container" "test_container" { + node_name = "{{.NodeName}}" + vm_id = {{.TestContainerID}} + timeout_delete = 10 + unprivileged = true + disk { + datastore_id = "local-lvm" + size = 4 + } + mount_point { + volume = "local-lvm" + size = "4G" + path = "mnt/local" + } + device_passthrough { + path = "/dev/zero" + } + description = <<-EOT + my + description + value + EOT + initialization { + hostname = "test" + ip_config { + ipv4 { + address = "172.16.10.10/15" + gateway = "172.16.0.1" + } + } + } + network_interface { + name = "vmbr0" + } + operating_system { + template_file_id = "local:vztmpl/{{.ImageFileName}}" + type = "ubuntu" + } + }`, WithRootUser()), + Check: resource.ComposeTestCheckFunc( + ResourceAttributes(accTestContainerName, map[string]string{ + "disk.0.mount_options.#": "0", }), ), }, diff --git a/proxmox/nodes/containers/containers_types.go b/proxmox/nodes/containers/containers_types.go index f6df4a81..3663e2d1 100644 --- a/proxmox/nodes/containers/containers_types.go +++ b/proxmox/nodes/containers/containers_types.go @@ -875,6 +875,8 @@ func (r *CustomRootFS) UnmarshalJSON(b []byte) error { r.Volume = v[0] } else if len(v) == 2 { switch v[0] { + case "volume": + r.Volume = v[1] case "acl": bv := types.CustomBool(v[1] == "1") r.ACL = &bv @@ -902,7 +904,7 @@ func (r *CustomRootFS) UnmarshalJSON(b []byte) error { case "size": r.Size = new(types.DiskSize) - err := r.Size.UnmarshalJSON([]byte(v[1])) + err = r.Size.UnmarshalJSON([]byte(v[1])) if err != nil { return fmt.Errorf("failed to unmarshal disk size: %w", err) } diff --git a/proxmoxtf/resource/container/container.go b/proxmoxtf/resource/container/container.go index 5de3564a..58435cf7 100644 --- a/proxmoxtf/resource/container/container.go +++ b/proxmoxtf/resource/container/container.go @@ -2310,10 +2310,6 @@ func containerRead(ctx context.Context, d *schema.ResourceData, m interface{}) d // Default value of "storage" is "local" according to the API documentation. disk[mkDiskDatastoreID] = "local" disk[mkDiskSize] = dvDiskSize - disk[mkDiskMountOptions] = nil - disk[mkDiskACL] = dvDiskACL - disk[mkDiskReplicate] = dvDiskReplicate - disk[mkDiskQuota] = dvDiskQuota } currentDisk := d.Get(mkDisk).([]interface{}) @@ -3016,6 +3012,8 @@ func containerUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) } updateBody.RootFS = rootFS + + rebootRequired = true } if d.HasChange(mkFeatures) {