mirror of
https://github.com/bpg/terraform-provider-proxmox.git
synced 2025-07-05 05:24:01 +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`)
|
to `false`)
|
||||||
- `keyctl` - (Optional) Whether the container supports `keyctl()` system
|
- `keyctl` - (Optional) Whether the container supports `keyctl()` system
|
||||||
call (defaults to `false`)
|
call (defaults to `false`)
|
||||||
|
- `mount` - (Optional) List of allowed mount types (`cifs` or `nfs`)
|
||||||
|
|
||||||
## Attribute Reference
|
## Attribute Reference
|
||||||
|
|
||||||
|
@ -92,6 +92,7 @@ const (
|
|||||||
mkResourceVirtualEnvironmentContainerFeaturesNesting = "nesting"
|
mkResourceVirtualEnvironmentContainerFeaturesNesting = "nesting"
|
||||||
mkResourceVirtualEnvironmentContainerFeaturesKeyControl = "keyctl"
|
mkResourceVirtualEnvironmentContainerFeaturesKeyControl = "keyctl"
|
||||||
mkResourceVirtualEnvironmentContainerFeaturesFUSE = "fuse"
|
mkResourceVirtualEnvironmentContainerFeaturesFUSE = "fuse"
|
||||||
|
mkResourceVirtualEnvironmentContainerFeaturesMountTypes = "mount"
|
||||||
mkResourceVirtualEnvironmentContainerInitialization = "initialization"
|
mkResourceVirtualEnvironmentContainerInitialization = "initialization"
|
||||||
mkResourceVirtualEnvironmentContainerInitializationDNS = "dns"
|
mkResourceVirtualEnvironmentContainerInitializationDNS = "dns"
|
||||||
mkResourceVirtualEnvironmentContainerInitializationDNSDomain = "domain"
|
mkResourceVirtualEnvironmentContainerInitializationDNSDomain = "domain"
|
||||||
@ -315,13 +316,13 @@ func Container() *schema.Resource {
|
|||||||
Type: schema.TypeList,
|
Type: schema.TypeList,
|
||||||
Description: "Features",
|
Description: "Features",
|
||||||
Optional: true,
|
Optional: true,
|
||||||
ForceNew: true,
|
|
||||||
DefaultFunc: func() (interface{}, error) {
|
DefaultFunc: func() (interface{}, error) {
|
||||||
return []interface{}{
|
return []interface{}{
|
||||||
map[string]interface{}{
|
map[string]interface{}{
|
||||||
mkResourceVirtualEnvironmentContainerFeaturesNesting: dvResourceVirtualEnvironmentContainerFeaturesNesting,
|
mkResourceVirtualEnvironmentContainerFeaturesNesting: dvResourceVirtualEnvironmentContainerFeaturesNesting,
|
||||||
mkResourceVirtualEnvironmentContainerFeaturesKeyControl: dvResourceVirtualEnvironmentContainerFeaturesKeyControl,
|
mkResourceVirtualEnvironmentContainerFeaturesKeyControl: dvResourceVirtualEnvironmentContainerFeaturesKeyControl,
|
||||||
mkResourceVirtualEnvironmentContainerFeaturesFUSE: dvResourceVirtualEnvironmentContainerFeaturesFUSE,
|
mkResourceVirtualEnvironmentContainerFeaturesFUSE: dvResourceVirtualEnvironmentContainerFeaturesFUSE,
|
||||||
|
mkResourceVirtualEnvironmentContainerFeaturesMountTypes: []interface{}{},
|
||||||
},
|
},
|
||||||
}, nil
|
}, nil
|
||||||
},
|
},
|
||||||
@ -331,23 +332,29 @@ func Container() *schema.Resource {
|
|||||||
Type: schema.TypeBool,
|
Type: schema.TypeBool,
|
||||||
Description: "Whether the container runs as nested",
|
Description: "Whether the container runs as nested",
|
||||||
Optional: true,
|
Optional: true,
|
||||||
ForceNew: true,
|
|
||||||
Default: dvResourceVirtualEnvironmentContainerFeaturesNesting,
|
Default: dvResourceVirtualEnvironmentContainerFeaturesNesting,
|
||||||
},
|
},
|
||||||
mkResourceVirtualEnvironmentContainerFeaturesKeyControl: {
|
mkResourceVirtualEnvironmentContainerFeaturesKeyControl: {
|
||||||
Type: schema.TypeBool,
|
Type: schema.TypeBool,
|
||||||
Description: "Whether the container supports `keyctl()` system call",
|
Description: "Whether the container supports `keyctl()` system call",
|
||||||
Optional: true,
|
Optional: true,
|
||||||
ForceNew: true,
|
|
||||||
Default: dvResourceVirtualEnvironmentContainerFeaturesKeyControl,
|
Default: dvResourceVirtualEnvironmentContainerFeaturesKeyControl,
|
||||||
},
|
},
|
||||||
mkResourceVirtualEnvironmentContainerFeaturesFUSE: {
|
mkResourceVirtualEnvironmentContainerFeaturesFUSE: {
|
||||||
Type: schema.TypeBool,
|
Type: schema.TypeBool,
|
||||||
Description: "Whether the container supports FUSE mounts",
|
Description: "Whether the container supports FUSE mounts",
|
||||||
Optional: true,
|
Optional: true,
|
||||||
ForceNew: true,
|
|
||||||
Default: dvResourceVirtualEnvironmentContainerFeaturesFUSE,
|
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,
|
MaxItems: 1,
|
||||||
@ -1216,35 +1223,11 @@ func containerCreateCustom(ctx context.Context, d *schema.ResourceData, m interf
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
featuresBlock, err := structure.GetSchemaBlock(
|
features, err := containerGetFeatures(resource, d)
|
||||||
resource,
|
|
||||||
d,
|
|
||||||
[]string{mkResourceVirtualEnvironmentContainerFeatures},
|
|
||||||
0,
|
|
||||||
true,
|
|
||||||
)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
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{})
|
initialization := d.Get(mkResourceVirtualEnvironmentContainerInitialization).([]interface{})
|
||||||
initializationDNSDomain := dvResourceVirtualEnvironmentContainerInitializationDNSDomain
|
initializationDNSDomain := dvResourceVirtualEnvironmentContainerInitializationDNSDomain
|
||||||
initializationDNSServer := dvResourceVirtualEnvironmentContainerInitializationDNSServer
|
initializationDNSServer := dvResourceVirtualEnvironmentContainerInitializationDNSServer
|
||||||
@ -1494,7 +1477,7 @@ func containerCreateCustom(ctx context.Context, d *schema.ResourceData, m interf
|
|||||||
CPUUnits: &cpuUnits,
|
CPUUnits: &cpuUnits,
|
||||||
DatastoreID: &diskDatastoreID,
|
DatastoreID: &diskDatastoreID,
|
||||||
DedicatedMemory: &memoryDedicated,
|
DedicatedMemory: &memoryDedicated,
|
||||||
Features: &features,
|
Features: features,
|
||||||
MountPoints: mountPointArray,
|
MountPoints: mountPointArray,
|
||||||
NetworkInterfaces: networkInterfaceArray,
|
NetworkInterfaces: networkInterfaceArray,
|
||||||
OSTemplateFileVolume: &operatingSystemTemplateFileID,
|
OSTemplateFileVolume: &operatingSystemTemplateFileID,
|
||||||
@ -1711,6 +1694,52 @@ func containerGetTagsString(d *schema.ResourceData) string {
|
|||||||
return strings.Join(sanitizedTags, ";")
|
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 {
|
func containerRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||||
var diags diag.Diagnostics
|
var diags diag.Diagnostics
|
||||||
|
|
||||||
@ -2363,6 +2392,15 @@ func containerUpdate(ctx context.Context, d *schema.ResourceData, m interface{})
|
|||||||
rebootRequired = true
|
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.
|
// Prepare the new initialization configuration.
|
||||||
initialization := d.Get(mkResourceVirtualEnvironmentContainerInitialization).([]interface{})
|
initialization := d.Get(mkResourceVirtualEnvironmentContainerInitialization).([]interface{})
|
||||||
initializationDNSDomain := dvResourceVirtualEnvironmentContainerInitializationDNSDomain
|
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