mirror of
https://github.com/bpg/terraform-provider-proxmox.git
synced 2025-07-01 19:12:59 +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
|
- `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`)
|
- `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
|
## Attribute Reference
|
||||||
|
|
||||||
|
@ -49,6 +49,7 @@ const (
|
|||||||
dvFeaturesNesting = false
|
dvFeaturesNesting = false
|
||||||
dvFeaturesKeyControl = false
|
dvFeaturesKeyControl = false
|
||||||
dvFeaturesFUSE = false
|
dvFeaturesFUSE = false
|
||||||
|
dvHookScript = ""
|
||||||
dvMemoryDedicated = 512
|
dvMemoryDedicated = 512
|
||||||
dvMemorySwap = 0
|
dvMemorySwap = 0
|
||||||
dvMountPointACL = false
|
dvMountPointACL = false
|
||||||
@ -100,6 +101,7 @@ const (
|
|||||||
mkFeaturesKeyControl = "keyctl"
|
mkFeaturesKeyControl = "keyctl"
|
||||||
mkFeaturesFUSE = "fuse"
|
mkFeaturesFUSE = "fuse"
|
||||||
mkFeaturesMountTypes = "mount"
|
mkFeaturesMountTypes = "mount"
|
||||||
|
mkHookScriptFileID = "hook_script_file_id"
|
||||||
mkInitialization = "initialization"
|
mkInitialization = "initialization"
|
||||||
mkInitializationDNS = "dns"
|
mkInitializationDNS = "dns"
|
||||||
mkInitializationDNSDomain = "domain"
|
mkInitializationDNSDomain = "domain"
|
||||||
@ -375,6 +377,12 @@ func Container() *schema.Resource {
|
|||||||
MaxItems: 1,
|
MaxItems: 1,
|
||||||
MinItems: 0,
|
MinItems: 0,
|
||||||
},
|
},
|
||||||
|
mkHookScriptFileID: {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Description: "A hook script",
|
||||||
|
Optional: true,
|
||||||
|
Default: dvHookScript,
|
||||||
|
},
|
||||||
mkInitialization: {
|
mkInitialization: {
|
||||||
Type: schema.TypeList,
|
Type: schema.TypeList,
|
||||||
Description: "The initialization configuration",
|
Description: "The initialization configuration",
|
||||||
@ -996,6 +1004,12 @@ func containerCreateClone(ctx context.Context, d *schema.ResourceData, m interfa
|
|||||||
updateBody.CPUUnits = &cpuUnits
|
updateBody.CPUUnits = &cpuUnits
|
||||||
}
|
}
|
||||||
|
|
||||||
|
hookScript := d.Get(mkHookScriptFileID).(string)
|
||||||
|
|
||||||
|
if hookScript != "" {
|
||||||
|
updateBody.HookScript = &hookScript
|
||||||
|
}
|
||||||
|
|
||||||
var initializationIPConfigIPv4Address []string
|
var initializationIPConfigIPv4Address []string
|
||||||
|
|
||||||
var initializationIPConfigIPv4Gateway []string
|
var initializationIPConfigIPv4Gateway []string
|
||||||
@ -1316,6 +1330,8 @@ func containerCreateCustom(ctx context.Context, d *schema.ResourceData, m interf
|
|||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
hookScript := d.Get(mkHookScriptFileID).(string)
|
||||||
|
|
||||||
initialization := d.Get(mkInitialization).([]interface{})
|
initialization := d.Get(mkInitialization).([]interface{})
|
||||||
initializationDNSDomain := dvInitializationDNSDomain
|
initializationDNSDomain := dvInitializationDNSDomain
|
||||||
initializationDNSServer := dvInitializationDNSServer
|
initializationDNSServer := dvInitializationDNSServer
|
||||||
@ -1632,6 +1648,10 @@ func containerCreateCustom(ctx context.Context, d *schema.ResourceData, m interf
|
|||||||
createBody.Description = &description
|
createBody.Description = &description
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if hookScript != "" {
|
||||||
|
createBody.HookScript = &hookScript
|
||||||
|
}
|
||||||
|
|
||||||
if initializationDNSDomain != "" {
|
if initializationDNSDomain != "" {
|
||||||
createBody.DNSDomain = &initializationDNSDomain
|
createBody.DNSDomain = &initializationDNSDomain
|
||||||
}
|
}
|
||||||
@ -2597,6 +2617,15 @@ func containerUpdate(ctx context.Context, d *schema.ResourceData, m interface{})
|
|||||||
updateBody.Features = features
|
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.
|
// Prepare the new initialization configuration.
|
||||||
initialization := d.Get(mkInitialization).([]interface{})
|
initialization := d.Get(mkInitialization).([]interface{})
|
||||||
initializationDNSDomain := dvInitializationDNSDomain
|
initializationDNSDomain := dvInitializationDNSDomain
|
||||||
|
@ -39,6 +39,7 @@ func TestContainerSchema(t *testing.T) {
|
|||||||
mkDescription,
|
mkDescription,
|
||||||
mkDisk,
|
mkDisk,
|
||||||
mkInitialization,
|
mkInitialization,
|
||||||
|
mkHookScriptFileID,
|
||||||
mkMemory,
|
mkMemory,
|
||||||
mkMountPoint,
|
mkMountPoint,
|
||||||
mkOperatingSystem,
|
mkOperatingSystem,
|
||||||
@ -53,21 +54,22 @@ func TestContainerSchema(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
test.AssertValueTypes(t, s, map[string]schema.ValueType{
|
test.AssertValueTypes(t, s, map[string]schema.ValueType{
|
||||||
mkCPU: schema.TypeList,
|
mkCPU: schema.TypeList,
|
||||||
mkDescription: schema.TypeString,
|
mkDescription: schema.TypeString,
|
||||||
mkDisk: schema.TypeList,
|
mkDisk: schema.TypeList,
|
||||||
mkInitialization: schema.TypeList,
|
mkInitialization: schema.TypeList,
|
||||||
mkMemory: schema.TypeList,
|
mkHookScriptFileID: schema.TypeString,
|
||||||
mkMountPoint: schema.TypeList,
|
mkMemory: schema.TypeList,
|
||||||
mkOperatingSystem: schema.TypeList,
|
mkMountPoint: schema.TypeList,
|
||||||
mkPoolID: schema.TypeString,
|
mkOperatingSystem: schema.TypeList,
|
||||||
mkStarted: schema.TypeBool,
|
mkPoolID: schema.TypeString,
|
||||||
mkTags: schema.TypeList,
|
mkStarted: schema.TypeBool,
|
||||||
mkTemplate: schema.TypeBool,
|
mkTags: schema.TypeList,
|
||||||
mkUnprivileged: schema.TypeBool,
|
mkTemplate: schema.TypeBool,
|
||||||
mkStartOnBoot: schema.TypeBool,
|
mkUnprivileged: schema.TypeBool,
|
||||||
mkFeatures: schema.TypeList,
|
mkStartOnBoot: schema.TypeBool,
|
||||||
mkVMID: schema.TypeInt,
|
mkFeatures: schema.TypeList,
|
||||||
|
mkVMID: schema.TypeInt,
|
||||||
})
|
})
|
||||||
|
|
||||||
cloneSchema := test.AssertNestedSchemaExistence(t, s, mkClone)
|
cloneSchema := test.AssertNestedSchemaExistence(t, s, mkClone)
|
||||||
|
Loading…
Reference in New Issue
Block a user