mirror of
https://github.com/bpg/terraform-provider-proxmox.git
synced 2025-07-04 21:14:05 +00:00
fix(lxc): add new storage-backed mount point to existing container (#1553)
Signed-off-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com>
This commit is contained in:
parent
6f6e4a923c
commit
89d72cd37f
@ -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"
|
||||
|
@ -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
|
||||
|
||||
// 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))
|
||||
|
Loading…
Reference in New Issue
Block a user