mirror of
https://github.com/bpg/terraform-provider-proxmox.git
synced 2025-07-04 12:32:59 +00:00
fix(lxc): fixes for datastore-backed volume mounts (#772)
Signed-off-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com>
This commit is contained in:
parent
52f17defda
commit
25deebba26
@ -47,8 +47,16 @@ resource "proxmox_virtual_environment_container" "ubuntu_container" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
mount_point {
|
mount_point {
|
||||||
|
# bind mount, *requires* root@pam authentication
|
||||||
volume = "/mnt/bindmounts/shared"
|
volume = "/mnt/bindmounts/shared"
|
||||||
path = "/shared"
|
path = "/mnt/shared"
|
||||||
|
}
|
||||||
|
|
||||||
|
mount_point {
|
||||||
|
# volume mount, a new volume will be created by PVE
|
||||||
|
volume = "local-lvm"
|
||||||
|
size = "10G"
|
||||||
|
path = "/mnt/volume"
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -155,7 +163,7 @@ output "ubuntu_container_public_key" {
|
|||||||
- `replicate` (Optional) Will include this volume to a storage replica job.
|
- `replicate` (Optional) Will include this volume to a storage replica job.
|
||||||
- `shared` (Optional) Mark this non-volume mount point as available on all
|
- `shared` (Optional) Mark this non-volume mount point as available on all
|
||||||
nodes.
|
nodes.
|
||||||
- `size` (Optional) Volume size (only for ZFS storage backed mount points).
|
- `size` (Optional) Volume size (only for volume mount points).
|
||||||
Can be specified with a unit suffix (e.g. `10G`).
|
Can be specified with a unit suffix (e.g. `10G`).
|
||||||
- `volume` (Required) Volume, device or directory to mount into the
|
- `volume` (Required) Volume, device or directory to mount into the
|
||||||
container.
|
container.
|
||||||
|
@ -6,6 +6,13 @@ resource "proxmox_virtual_environment_container" "example_template" {
|
|||||||
size = 10
|
size = 10
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mount_point {
|
||||||
|
// volume mount
|
||||||
|
volume = element(data.proxmox_virtual_environment_datastores.example.datastore_ids, index(data.proxmox_virtual_environment_datastores.example.datastore_ids, "local-lvm"))
|
||||||
|
size = "4G"
|
||||||
|
path = "mnt/local"
|
||||||
|
}
|
||||||
|
|
||||||
initialization {
|
initialization {
|
||||||
dns {
|
dns {
|
||||||
server = "1.1.1.1"
|
server = "1.1.1.1"
|
||||||
@ -63,6 +70,7 @@ resource "proxmox_virtual_environment_container" "example" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
mount_point {
|
mount_point {
|
||||||
|
// bind mount, requires root@pam
|
||||||
volume = "/mnt/bindmounts/shared"
|
volume = "/mnt/bindmounts/shared"
|
||||||
path = "/shared"
|
path = "/shared"
|
||||||
}
|
}
|
||||||
|
@ -51,6 +51,7 @@ const (
|
|||||||
dvResourceVirtualEnvironmentContainerMemorySwap = 0
|
dvResourceVirtualEnvironmentContainerMemorySwap = 0
|
||||||
dvResourceVirtualEnvironmentContainerMountPointACL = false
|
dvResourceVirtualEnvironmentContainerMountPointACL = false
|
||||||
dvResourceVirtualEnvironmentContainerMountPointBackup = true
|
dvResourceVirtualEnvironmentContainerMountPointBackup = true
|
||||||
|
dvResourceVirtualEnvironmentContainerMountPointPath = ""
|
||||||
dvResourceVirtualEnvironmentContainerMountPointQuota = false
|
dvResourceVirtualEnvironmentContainerMountPointQuota = false
|
||||||
dvResourceVirtualEnvironmentContainerMountPointReadOnly = false
|
dvResourceVirtualEnvironmentContainerMountPointReadOnly = false
|
||||||
dvResourceVirtualEnvironmentContainerMountPointReplicate = true
|
dvResourceVirtualEnvironmentContainerMountPointReplicate = true
|
||||||
@ -576,10 +577,17 @@ func Container() *schema.Resource {
|
|||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Description: "Path to the mount point as seen from inside the container",
|
Description: "Path to the mount point as seen from inside the container",
|
||||||
Required: true,
|
Required: true,
|
||||||
|
// StateFunc: func(i interface{}) string {
|
||||||
|
// // PVE strips leading slashes from the path, so we have to do the same
|
||||||
|
// return strings.TrimPrefix(i.(string), "/")
|
||||||
|
// },
|
||||||
|
DiffSuppressFunc: func(k, oldVal, newVal string, d *schema.ResourceData) bool {
|
||||||
|
return "/"+oldVal == newVal
|
||||||
|
},
|
||||||
},
|
},
|
||||||
mkResourceVirtualEnvironmentContainerMountPointQuota: {
|
mkResourceVirtualEnvironmentContainerMountPointQuota: {
|
||||||
Type: schema.TypeBool,
|
Type: schema.TypeBool,
|
||||||
Description: "Enable user quotas inside the container (not supported with zfs subvolumes)",
|
Description: "Enable user quotas inside the container (not supported with volume mounts)",
|
||||||
Optional: true,
|
Optional: true,
|
||||||
Default: dvResourceVirtualEnvironmentContainerMountPointQuota,
|
Default: dvResourceVirtualEnvironmentContainerMountPointQuota,
|
||||||
},
|
},
|
||||||
@ -612,6 +620,16 @@ func Container() *schema.Resource {
|
|||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Description: "Volume, device or directory to mount into the container",
|
Description: "Volume, device or directory to mount into the container",
|
||||||
Required: true,
|
Required: true,
|
||||||
|
DiffSuppressFunc: func(k, oldVal, newVal string, d *schema.ResourceData) bool {
|
||||||
|
// For *new* volume mounts PVE returns an actual volume ID which is saved in the stare,
|
||||||
|
// so on reapply the provider will try override it:"
|
||||||
|
// "local-lvm" -> "local-lvm:vm-101-disk-1"
|
||||||
|
// "local-lvm:8" -> "local-lvm:vm-101-disk-1"
|
||||||
|
// There is also an option to mount an existing volume, so
|
||||||
|
// "local-lvm:vm-101-disk-1" -> "local-lvm:vm-101-disk-1"
|
||||||
|
// which is a valid case.
|
||||||
|
return oldVal == newVal || strings.HasPrefix(oldVal, strings.Split(newVal, ":")[0]+":")
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -1330,6 +1348,8 @@ func containerCreateCustom(ctx context.Context, d *schema.ResourceData, m interf
|
|||||||
mountPoint := d.Get(mkResourceVirtualEnvironmentContainerMountPoint).([]interface{})
|
mountPoint := d.Get(mkResourceVirtualEnvironmentContainerMountPoint).([]interface{})
|
||||||
mountPointArray := make(containers.CustomMountPointArray, 0, len(mountPoint))
|
mountPointArray := make(containers.CustomMountPointArray, 0, len(mountPoint))
|
||||||
|
|
||||||
|
// because of default bool values:
|
||||||
|
//nolint:gosimple
|
||||||
for _, mp := range mountPoint {
|
for _, mp := range mountPoint {
|
||||||
mountPointMap := mp.(map[string]interface{})
|
mountPointMap := mp.(map[string]interface{})
|
||||||
mountPointObject := containers.CustomMountPoint{}
|
mountPointObject := containers.CustomMountPoint{}
|
||||||
@ -1345,13 +1365,34 @@ func containerCreateCustom(ctx context.Context, d *schema.ResourceData, m interf
|
|||||||
size := mountPointMap[mkResourceVirtualEnvironmentContainerMountPointSize].(string)
|
size := mountPointMap[mkResourceVirtualEnvironmentContainerMountPointSize].(string)
|
||||||
volume := mountPointMap[mkResourceVirtualEnvironmentContainerMountPointVolume].(string)
|
volume := mountPointMap[mkResourceVirtualEnvironmentContainerMountPointVolume].(string)
|
||||||
|
|
||||||
|
// we have to set only the values that are different from the provider's defaults,
|
||||||
|
if acl != dvResourceVirtualEnvironmentContainerMountPointACL {
|
||||||
mountPointObject.ACL = &acl
|
mountPointObject.ACL = &acl
|
||||||
|
}
|
||||||
|
|
||||||
|
if backup != dvResourceVirtualEnvironmentContainerMountPointBackup {
|
||||||
mountPointObject.Backup = &backup
|
mountPointObject.Backup = &backup
|
||||||
|
}
|
||||||
|
|
||||||
|
if path != dvResourceVirtualEnvironmentContainerMountPointPath {
|
||||||
mountPointObject.MountPoint = path
|
mountPointObject.MountPoint = path
|
||||||
|
}
|
||||||
|
|
||||||
|
if quota != dvResourceVirtualEnvironmentContainerMountPointQuota {
|
||||||
mountPointObject.Quota = "a
|
mountPointObject.Quota = "a
|
||||||
|
}
|
||||||
|
|
||||||
|
if readOnly != dvResourceVirtualEnvironmentContainerMountPointReadOnly {
|
||||||
mountPointObject.ReadOnly = &readOnly
|
mountPointObject.ReadOnly = &readOnly
|
||||||
|
}
|
||||||
|
|
||||||
|
if replicate != dvResourceVirtualEnvironmentContainerMountPointReplicate {
|
||||||
mountPointObject.Replicate = &replicate
|
mountPointObject.Replicate = &replicate
|
||||||
|
}
|
||||||
|
|
||||||
|
if shared != dvResourceVirtualEnvironmentContainerMountPointShared {
|
||||||
mountPointObject.Shared = &shared
|
mountPointObject.Shared = &shared
|
||||||
|
}
|
||||||
|
|
||||||
if len(size) > 0 {
|
if len(size) > 0 {
|
||||||
var ds types.DiskSize
|
var ds types.DiskSize
|
||||||
|
Loading…
Reference in New Issue
Block a user