mirror of
https://github.com/bpg/terraform-provider-proxmox.git
synced 2025-06-30 10:33:46 +00:00
feat(vm): Support hook script (#733)
for vms, relates to #570 Signed-off-by: Simplysoft GmbH <1588210+simplysoft@users.noreply.github.com>
This commit is contained in:
parent
a96a3a9641
commit
0eb04b2a25
@ -500,6 +500,7 @@ output "ubuntu_vm_public_key" {
|
||||
- `virtio` - VirtIO-GPU.
|
||||
- `vmware` - VMware Compatible.
|
||||
- `vm_id` - (Optional) The VM identifier.
|
||||
- `hook_script_file_id` - (Optional) The identifier for a file containing a hook script (needs to be executable).
|
||||
|
||||
## Attribute Reference
|
||||
|
||||
|
@ -136,6 +136,8 @@ const (
|
||||
dvResourceVirtualEnvironmentVMVGAType = "std"
|
||||
dvResourceVirtualEnvironmentVMSCSIHardware = "virtio-scsi-pci"
|
||||
|
||||
dvResourceVirtualEnvironmentVMHookScript = ""
|
||||
|
||||
maxResourceVirtualEnvironmentVMAudioDevices = 1
|
||||
maxResourceVirtualEnvironmentVMNetworkDevices = 8
|
||||
maxResourceVirtualEnvironmentVMSerialDevices = 4
|
||||
@ -291,6 +293,7 @@ const (
|
||||
mkResourceVirtualEnvironmentVMVGAType = "type"
|
||||
mkResourceVirtualEnvironmentVMVMID = "vm_id"
|
||||
mkResourceVirtualEnvironmentVMSCSIHardware = "scsi_hardware"
|
||||
mkResourceVirtualEnvironmentVMHookScriptFileID = "hook_script_file_id"
|
||||
)
|
||||
|
||||
// VM returns a resource that manages VMs.
|
||||
@ -1530,6 +1533,12 @@ func VM() *schema.Resource {
|
||||
Default: dvResourceVirtualEnvironmentVMSCSIHardware,
|
||||
ValidateDiagFunc: validator.SCSIHardware(),
|
||||
},
|
||||
mkResourceVirtualEnvironmentVMHookScriptFileID: {
|
||||
Type: schema.TypeString,
|
||||
Description: "A hook script",
|
||||
Optional: true,
|
||||
Default: dvResourceVirtualEnvironmentVMHookScript,
|
||||
},
|
||||
},
|
||||
CreateContext: vmCreate,
|
||||
ReadContext: vmRead,
|
||||
@ -2121,6 +2130,13 @@ func vmCreateClone(ctx context.Context, d *schema.ResourceData, m interface{}) d
|
||||
updateBody.VGADevice = vgaDevice
|
||||
}
|
||||
|
||||
hookScript := d.Get(mkResourceVirtualEnvironmentVMHookScriptFileID).(string)
|
||||
if len(hookScript) > 0 {
|
||||
updateBody.HookScript = &hookScript
|
||||
} else {
|
||||
del = append(del, "hookscript")
|
||||
}
|
||||
|
||||
updateBody.Delete = del
|
||||
|
||||
e = vmAPI.UpdateVM(ctx, updateBody)
|
||||
@ -2655,6 +2671,11 @@ func vmCreateCustom(ctx context.Context, d *schema.ResourceData, m interface{})
|
||||
createBody.PoolID = &poolID
|
||||
}
|
||||
|
||||
hookScript := d.Get(mkResourceVirtualEnvironmentVMHookScriptFileID).(string)
|
||||
if len(hookScript) > 0 {
|
||||
createBody.HookScript = &hookScript
|
||||
}
|
||||
|
||||
createTimeout := d.Get(mkResourceVirtualEnvironmentVMTimeoutClone).(int)
|
||||
|
||||
err = api.Node(nodeName).VM(0).CreateVM(ctx, createBody, createTimeout)
|
||||
@ -5641,6 +5662,15 @@ func vmUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.D
|
||||
rebootRequired = true
|
||||
}
|
||||
|
||||
if d.HasChanges(mkResourceVirtualEnvironmentVMHookScriptFileID) {
|
||||
hookScript := d.Get(mkResourceVirtualEnvironmentVMHookScriptFileID).(string)
|
||||
if len(hookScript) > 0 {
|
||||
updateBody.HookScript = &hookScript
|
||||
} else {
|
||||
del = append(del, "hookscript")
|
||||
}
|
||||
}
|
||||
|
||||
// Update the configuration now that everything has been prepared.
|
||||
updateBody.Delete = del
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user