mirror of
https://github.com/bpg/terraform-provider-proxmox.git
synced 2025-07-04 21:14:05 +00:00
feat(lxc)!: allow to update features
, add mount type support (#765)
* feat(lxc): allow to update features, add mount type support Signed-off-by: tarik02 <taras.fomin@gmail.com> * updates according to the MR Signed-off-by: tarik02 <taras.fomin@gmail.com> * update according to the pull request Signed-off-by: tarik02 <taras.fomin@gmail.com> --------- Signed-off-by: tarik02 <taras.fomin@gmail.com>
This commit is contained in:
parent
7505b37708
commit
8bf26099e0
@ -205,6 +205,7 @@ output "ubuntu_container_public_key" {
|
||||
to `false`)
|
||||
- `keyctl` - (Optional) Whether the container supports `keyctl()` system
|
||||
call (defaults to `false`)
|
||||
- `mount` - (Optional) List of allowed mount types (`cifs` or `nfs`)
|
||||
|
||||
## Attribute Reference
|
||||
|
||||
|
@ -92,6 +92,7 @@ const (
|
||||
mkResourceVirtualEnvironmentContainerFeaturesNesting = "nesting"
|
||||
mkResourceVirtualEnvironmentContainerFeaturesKeyControl = "keyctl"
|
||||
mkResourceVirtualEnvironmentContainerFeaturesFUSE = "fuse"
|
||||
mkResourceVirtualEnvironmentContainerFeaturesMountTypes = "mount"
|
||||
mkResourceVirtualEnvironmentContainerInitialization = "initialization"
|
||||
mkResourceVirtualEnvironmentContainerInitializationDNS = "dns"
|
||||
mkResourceVirtualEnvironmentContainerInitializationDNSDomain = "domain"
|
||||
@ -315,13 +316,13 @@ func Container() *schema.Resource {
|
||||
Type: schema.TypeList,
|
||||
Description: "Features",
|
||||
Optional: true,
|
||||
ForceNew: true,
|
||||
DefaultFunc: func() (interface{}, error) {
|
||||
return []interface{}{
|
||||
map[string]interface{}{
|
||||
mkResourceVirtualEnvironmentContainerFeaturesNesting: dvResourceVirtualEnvironmentContainerFeaturesNesting,
|
||||
mkResourceVirtualEnvironmentContainerFeaturesKeyControl: dvResourceVirtualEnvironmentContainerFeaturesKeyControl,
|
||||
mkResourceVirtualEnvironmentContainerFeaturesFUSE: dvResourceVirtualEnvironmentContainerFeaturesFUSE,
|
||||
mkResourceVirtualEnvironmentContainerFeaturesMountTypes: []interface{}{},
|
||||
},
|
||||
}, nil
|
||||
},
|
||||
@ -331,23 +332,29 @@ func Container() *schema.Resource {
|
||||
Type: schema.TypeBool,
|
||||
Description: "Whether the container runs as nested",
|
||||
Optional: true,
|
||||
ForceNew: true,
|
||||
Default: dvResourceVirtualEnvironmentContainerFeaturesNesting,
|
||||
},
|
||||
mkResourceVirtualEnvironmentContainerFeaturesKeyControl: {
|
||||
Type: schema.TypeBool,
|
||||
Description: "Whether the container supports `keyctl()` system call",
|
||||
Optional: true,
|
||||
ForceNew: true,
|
||||
Default: dvResourceVirtualEnvironmentContainerFeaturesKeyControl,
|
||||
},
|
||||
mkResourceVirtualEnvironmentContainerFeaturesFUSE: {
|
||||
Type: schema.TypeBool,
|
||||
Description: "Whether the container supports FUSE mounts",
|
||||
Optional: true,
|
||||
ForceNew: true,
|
||||
Default: dvResourceVirtualEnvironmentContainerFeaturesFUSE,
|
||||
},
|
||||
mkResourceVirtualEnvironmentContainerFeaturesMountTypes: {
|
||||
Type: schema.TypeList,
|
||||
Description: "List of allowed mount types",
|
||||
Optional: true,
|
||||
Elem: &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
ValidateDiagFunc: validator.MountType(),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
MaxItems: 1,
|
||||
@ -1216,35 +1223,11 @@ func containerCreateCustom(ctx context.Context, d *schema.ResourceData, m interf
|
||||
}
|
||||
}
|
||||
|
||||
featuresBlock, err := structure.GetSchemaBlock(
|
||||
resource,
|
||||
d,
|
||||
[]string{mkResourceVirtualEnvironmentContainerFeatures},
|
||||
0,
|
||||
true,
|
||||
)
|
||||
features, err := containerGetFeatures(resource, d)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
nesting := types.CustomBool(featuresBlock[mkResourceVirtualEnvironmentContainerFeaturesNesting].(bool))
|
||||
keyctl := types.CustomBool(featuresBlock[mkResourceVirtualEnvironmentContainerFeaturesKeyControl].(bool))
|
||||
fuse := types.CustomBool(featuresBlock[mkResourceVirtualEnvironmentContainerFeaturesFUSE].(bool))
|
||||
|
||||
features := containers.CustomFeatures{}
|
||||
|
||||
if nesting {
|
||||
features.Nesting = &nesting
|
||||
}
|
||||
|
||||
if keyctl {
|
||||
features.KeyControl = &keyctl
|
||||
}
|
||||
|
||||
if fuse {
|
||||
features.FUSE = &fuse
|
||||
}
|
||||
|
||||
initialization := d.Get(mkResourceVirtualEnvironmentContainerInitialization).([]interface{})
|
||||
initializationDNSDomain := dvResourceVirtualEnvironmentContainerInitializationDNSDomain
|
||||
initializationDNSServer := dvResourceVirtualEnvironmentContainerInitializationDNSServer
|
||||
@ -1494,7 +1477,7 @@ func containerCreateCustom(ctx context.Context, d *schema.ResourceData, m interf
|
||||
CPUUnits: &cpuUnits,
|
||||
DatastoreID: &diskDatastoreID,
|
||||
DedicatedMemory: &memoryDedicated,
|
||||
Features: &features,
|
||||
Features: features,
|
||||
MountPoints: mountPointArray,
|
||||
NetworkInterfaces: networkInterfaceArray,
|
||||
OSTemplateFileVolume: &operatingSystemTemplateFileID,
|
||||
@ -1711,6 +1694,52 @@ func containerGetTagsString(d *schema.ResourceData) string {
|
||||
return strings.Join(sanitizedTags, ";")
|
||||
}
|
||||
|
||||
func containerGetFeatures(resource *schema.Resource, d *schema.ResourceData) (*containers.CustomFeatures, error) {
|
||||
featuresBlock, err := structure.GetSchemaBlock(
|
||||
resource,
|
||||
d,
|
||||
[]string{mkResourceVirtualEnvironmentContainerFeatures},
|
||||
0,
|
||||
true,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error getting container features from schema: %w", err)
|
||||
}
|
||||
|
||||
nesting := types.CustomBool(featuresBlock[mkResourceVirtualEnvironmentContainerFeaturesNesting].(bool))
|
||||
keyctl := types.CustomBool(featuresBlock[mkResourceVirtualEnvironmentContainerFeaturesKeyControl].(bool))
|
||||
fuse := types.CustomBool(featuresBlock[mkResourceVirtualEnvironmentContainerFeaturesFUSE].(bool))
|
||||
mountTypes := featuresBlock[mkResourceVirtualEnvironmentContainerFeaturesMountTypes].([]interface{})
|
||||
|
||||
var mountTypesConverted []string
|
||||
if mountTypes != nil {
|
||||
mountTypesConverted = make([]string, len(mountTypes))
|
||||
for i, mountType := range mountTypes {
|
||||
mountTypesConverted[i] = mountType.(string)
|
||||
}
|
||||
} else {
|
||||
mountTypesConverted = []string{}
|
||||
}
|
||||
|
||||
features := containers.CustomFeatures{
|
||||
MountTypes: &mountTypesConverted,
|
||||
}
|
||||
|
||||
if nesting {
|
||||
features.Nesting = &nesting
|
||||
}
|
||||
|
||||
if keyctl {
|
||||
features.KeyControl = &keyctl
|
||||
}
|
||||
|
||||
if fuse {
|
||||
features.FUSE = &fuse
|
||||
}
|
||||
|
||||
return &features, nil
|
||||
}
|
||||
|
||||
func containerRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||
var diags diag.Diagnostics
|
||||
|
||||
@ -2363,6 +2392,15 @@ func containerUpdate(ctx context.Context, d *schema.ResourceData, m interface{})
|
||||
rebootRequired = true
|
||||
}
|
||||
|
||||
if d.HasChange(mkResourceVirtualEnvironmentContainerFeatures) {
|
||||
features, err := containerGetFeatures(resource, d)
|
||||
if err != nil {
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
updateBody.Features = features
|
||||
}
|
||||
|
||||
// Prepare the new initialization configuration.
|
||||
initialization := d.Get(mkResourceVirtualEnvironmentContainerInitialization).([]interface{})
|
||||
initializationDNSDomain := dvResourceVirtualEnvironmentContainerInitializationDNSDomain
|
||||
|
20
proxmoxtf/resource/validator/container.go
Normal file
20
proxmoxtf/resource/validator/container.go
Normal file
@ -0,0 +1,20 @@
|
||||
/*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
package validator
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
|
||||
)
|
||||
|
||||
// MountType returns a schema validation function for a mount type on a lxc container.
|
||||
func MountType() schema.SchemaValidateDiagFunc {
|
||||
return validation.ToDiagFunc(validation.StringInSlice([]string{
|
||||
"cifs",
|
||||
"nfs",
|
||||
}, false))
|
||||
}
|
Loading…
Reference in New Issue
Block a user