mirror of
https://github.com/bpg/terraform-provider-proxmox.git
synced 2025-06-30 18:42:58 +00:00
feat(lxc): support hook script for LXC (#1140)
* feat(lxc): support hook script for LXC Signed-off-by: msdnna <extracker0mail@gmail.com> --------- Signed-off-by: msdnna <extracker0mail@gmail.com>
This commit is contained in:
parent
6f8a472981
commit
0deaf1801a
@ -225,6 +225,7 @@ output "ubuntu_container_public_key" {
|
||||
- `keyctl` - (Optional) Whether the container supports `keyctl()` system
|
||||
call (defaults to `false`)
|
||||
- `mount` - (Optional) List of allowed mount types (`cifs` or `nfs`)
|
||||
- `hook_script_file_id` - (Optional) The identifier for a file containing a hook script (needs to be executable).
|
||||
|
||||
## Attribute Reference
|
||||
|
||||
|
@ -49,6 +49,7 @@ const (
|
||||
dvFeaturesNesting = false
|
||||
dvFeaturesKeyControl = false
|
||||
dvFeaturesFUSE = false
|
||||
dvHookScript = ""
|
||||
dvMemoryDedicated = 512
|
||||
dvMemorySwap = 0
|
||||
dvMountPointACL = false
|
||||
@ -100,6 +101,7 @@ const (
|
||||
mkFeaturesKeyControl = "keyctl"
|
||||
mkFeaturesFUSE = "fuse"
|
||||
mkFeaturesMountTypes = "mount"
|
||||
mkHookScriptFileID = "hook_script_file_id"
|
||||
mkInitialization = "initialization"
|
||||
mkInitializationDNS = "dns"
|
||||
mkInitializationDNSDomain = "domain"
|
||||
@ -375,6 +377,12 @@ func Container() *schema.Resource {
|
||||
MaxItems: 1,
|
||||
MinItems: 0,
|
||||
},
|
||||
mkHookScriptFileID: {
|
||||
Type: schema.TypeString,
|
||||
Description: "A hook script",
|
||||
Optional: true,
|
||||
Default: dvHookScript,
|
||||
},
|
||||
mkInitialization: {
|
||||
Type: schema.TypeList,
|
||||
Description: "The initialization configuration",
|
||||
@ -996,6 +1004,12 @@ func containerCreateClone(ctx context.Context, d *schema.ResourceData, m interfa
|
||||
updateBody.CPUUnits = &cpuUnits
|
||||
}
|
||||
|
||||
hookScript := d.Get(mkHookScriptFileID).(string)
|
||||
|
||||
if hookScript != "" {
|
||||
updateBody.HookScript = &hookScript
|
||||
}
|
||||
|
||||
var initializationIPConfigIPv4Address []string
|
||||
|
||||
var initializationIPConfigIPv4Gateway []string
|
||||
@ -1316,6 +1330,8 @@ func containerCreateCustom(ctx context.Context, d *schema.ResourceData, m interf
|
||||
return diag.FromErr(err)
|
||||
}
|
||||
|
||||
hookScript := d.Get(mkHookScriptFileID).(string)
|
||||
|
||||
initialization := d.Get(mkInitialization).([]interface{})
|
||||
initializationDNSDomain := dvInitializationDNSDomain
|
||||
initializationDNSServer := dvInitializationDNSServer
|
||||
@ -1632,6 +1648,10 @@ func containerCreateCustom(ctx context.Context, d *schema.ResourceData, m interf
|
||||
createBody.Description = &description
|
||||
}
|
||||
|
||||
if hookScript != "" {
|
||||
createBody.HookScript = &hookScript
|
||||
}
|
||||
|
||||
if initializationDNSDomain != "" {
|
||||
createBody.DNSDomain = &initializationDNSDomain
|
||||
}
|
||||
@ -2597,6 +2617,15 @@ func containerUpdate(ctx context.Context, d *schema.ResourceData, m interface{})
|
||||
updateBody.Features = features
|
||||
}
|
||||
|
||||
if d.HasChange(mkHookScriptFileID) {
|
||||
hookScript := d.Get(mkHookScriptFileID).(string)
|
||||
if hookScript != "" {
|
||||
updateBody.HookScript = &hookScript
|
||||
} else {
|
||||
updateBody.Delete = append(updateBody.Delete, "hookscript")
|
||||
}
|
||||
}
|
||||
|
||||
// Prepare the new initialization configuration.
|
||||
initialization := d.Get(mkInitialization).([]interface{})
|
||||
initializationDNSDomain := dvInitializationDNSDomain
|
||||
|
@ -39,6 +39,7 @@ func TestContainerSchema(t *testing.T) {
|
||||
mkDescription,
|
||||
mkDisk,
|
||||
mkInitialization,
|
||||
mkHookScriptFileID,
|
||||
mkMemory,
|
||||
mkMountPoint,
|
||||
mkOperatingSystem,
|
||||
@ -53,21 +54,22 @@ func TestContainerSchema(t *testing.T) {
|
||||
})
|
||||
|
||||
test.AssertValueTypes(t, s, map[string]schema.ValueType{
|
||||
mkCPU: schema.TypeList,
|
||||
mkDescription: schema.TypeString,
|
||||
mkDisk: schema.TypeList,
|
||||
mkInitialization: schema.TypeList,
|
||||
mkMemory: schema.TypeList,
|
||||
mkMountPoint: schema.TypeList,
|
||||
mkOperatingSystem: schema.TypeList,
|
||||
mkPoolID: schema.TypeString,
|
||||
mkStarted: schema.TypeBool,
|
||||
mkTags: schema.TypeList,
|
||||
mkTemplate: schema.TypeBool,
|
||||
mkUnprivileged: schema.TypeBool,
|
||||
mkStartOnBoot: schema.TypeBool,
|
||||
mkFeatures: schema.TypeList,
|
||||
mkVMID: schema.TypeInt,
|
||||
mkCPU: schema.TypeList,
|
||||
mkDescription: schema.TypeString,
|
||||
mkDisk: schema.TypeList,
|
||||
mkInitialization: schema.TypeList,
|
||||
mkHookScriptFileID: schema.TypeString,
|
||||
mkMemory: schema.TypeList,
|
||||
mkMountPoint: schema.TypeList,
|
||||
mkOperatingSystem: schema.TypeList,
|
||||
mkPoolID: schema.TypeString,
|
||||
mkStarted: schema.TypeBool,
|
||||
mkTags: schema.TypeList,
|
||||
mkTemplate: schema.TypeBool,
|
||||
mkUnprivileged: schema.TypeBool,
|
||||
mkStartOnBoot: schema.TypeBool,
|
||||
mkFeatures: schema.TypeList,
|
||||
mkVMID: schema.TypeInt,
|
||||
})
|
||||
|
||||
cloneSchema := test.AssertNestedSchemaExistence(t, s, mkClone)
|
||||
|
Loading…
Reference in New Issue
Block a user