diff --git a/fwprovider/test/resource_container_test.go b/fwprovider/test/resource_container_test.go index b838fbae..560f24bb 100644 --- a/fwprovider/test/resource_container_test.go +++ b/fwprovider/test/resource_container_test.go @@ -111,10 +111,6 @@ func TestAccResourceContainer(t *testing.T) { }}}, {"update mount points", []resource.TestStep{ { - SkipFunc: func() (bool, error) { - // mount point deletion: https://github.com/bpg/terraform-provider-proxmox/issues/1392 - return true, nil - }, Config: te.RenderConfig(` resource "proxmox_virtual_environment_container" "test_container" { node_name = "{{.NodeName}}" @@ -128,11 +124,6 @@ func TestAccResourceContainer(t *testing.T) { volume = "local-lvm" size = "4G" path = "mnt/local1" - } - mount_point { - volume = "local" - size = "8G" - path = "mnt/local2" } initialization { hostname = "test" @@ -151,14 +142,10 @@ func TestAccResourceContainer(t *testing.T) { } }`), Check: ResourceAttributes("proxmox_virtual_environment_container.test_container", map[string]string{ - "mount_point.#": "2", + "mount_point.#": "1", }), }, { - SkipFunc: func() (bool, error) { - // mount point deletion: https://github.com/bpg/terraform-provider-proxmox/issues/1392 - return true, nil - }, Config: te.RenderConfig(` resource "proxmox_virtual_environment_container" "test_container" { node_name = "{{.NodeName}}" @@ -171,6 +158,12 @@ func TestAccResourceContainer(t *testing.T) { volume = "local-lvm" size = "4G" path = "mnt/local1" + } + // add a new mount point + mount_point { + volume = "local-lvm" + size = "4G" + path = "mnt/local2" } initialization { hostname = "test" diff --git a/proxmoxtf/resource/container/container.go b/proxmoxtf/resource/container/container.go index aff825f9..6d1404ce 100644 --- a/proxmoxtf/resource/container/container.go +++ b/proxmoxtf/resource/container/container.go @@ -2882,6 +2882,7 @@ func containerUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) readOnly := types.CustomBool(mountPointMap[mkMountPointReadOnly].(bool)) replicate := types.CustomBool(mountPointMap[mkMountPointReplicate].(bool)) shared := types.CustomBool(mountPointMap[mkMountPointShared].(bool)) + size := mountPointMap[mkMountPointSize].(string) volume := mountPointMap[mkMountPointVolume].(string) mountPointObject.ACL = &acl @@ -2891,7 +2892,26 @@ func containerUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) mountPointObject.ReadOnly = &readOnly mountPointObject.Replicate = &replicate mountPointObject.Shared = &shared - mountPointObject.Volume = volume + + // this is a totally hackish way to determine if the mount point is new or not during the container update. + // an attached storage-backed MP has volume in the format "storage:disk file", i.e. `local-lvm:vm-123-disk-1` + // while a new storage-backed MP has just plain volume name, i.e. `local-lvm` + // device or directory MPs won't have a colon in the volume name either, and we don't need to do the special + // handling for them. + createNewMP := !strings.Contains(volume, ":") + + if len(size) > 0 && createNewMP { + var ds types.DiskSize + + ds, err := types.ParseDiskSize(size) + if err != nil { + return diag.Errorf("invalid disk size: %s", err.Error()) + } + + mountPointObject.Volume = fmt.Sprintf("%s:%d", volume, ds.InGigabytes()) + } else { + mountPointObject.Volume = volume + } if len(mountOptions) > 0 { mountOptionsArray := make([]string, 0, len(mountPoints))