mirror of
https://github.com/bpg/terraform-provider-proxmox.git
synced 2025-07-01 02:52:58 +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.
|
- `virtio` - VirtIO-GPU.
|
||||||
- `vmware` - VMware Compatible.
|
- `vmware` - VMware Compatible.
|
||||||
- `vm_id` - (Optional) The VM identifier.
|
- `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
|
## Attribute Reference
|
||||||
|
|
||||||
|
@ -136,6 +136,8 @@ const (
|
|||||||
dvResourceVirtualEnvironmentVMVGAType = "std"
|
dvResourceVirtualEnvironmentVMVGAType = "std"
|
||||||
dvResourceVirtualEnvironmentVMSCSIHardware = "virtio-scsi-pci"
|
dvResourceVirtualEnvironmentVMSCSIHardware = "virtio-scsi-pci"
|
||||||
|
|
||||||
|
dvResourceVirtualEnvironmentVMHookScript = ""
|
||||||
|
|
||||||
maxResourceVirtualEnvironmentVMAudioDevices = 1
|
maxResourceVirtualEnvironmentVMAudioDevices = 1
|
||||||
maxResourceVirtualEnvironmentVMNetworkDevices = 8
|
maxResourceVirtualEnvironmentVMNetworkDevices = 8
|
||||||
maxResourceVirtualEnvironmentVMSerialDevices = 4
|
maxResourceVirtualEnvironmentVMSerialDevices = 4
|
||||||
@ -291,6 +293,7 @@ const (
|
|||||||
mkResourceVirtualEnvironmentVMVGAType = "type"
|
mkResourceVirtualEnvironmentVMVGAType = "type"
|
||||||
mkResourceVirtualEnvironmentVMVMID = "vm_id"
|
mkResourceVirtualEnvironmentVMVMID = "vm_id"
|
||||||
mkResourceVirtualEnvironmentVMSCSIHardware = "scsi_hardware"
|
mkResourceVirtualEnvironmentVMSCSIHardware = "scsi_hardware"
|
||||||
|
mkResourceVirtualEnvironmentVMHookScriptFileID = "hook_script_file_id"
|
||||||
)
|
)
|
||||||
|
|
||||||
// VM returns a resource that manages VMs.
|
// VM returns a resource that manages VMs.
|
||||||
@ -1530,6 +1533,12 @@ func VM() *schema.Resource {
|
|||||||
Default: dvResourceVirtualEnvironmentVMSCSIHardware,
|
Default: dvResourceVirtualEnvironmentVMSCSIHardware,
|
||||||
ValidateDiagFunc: validator.SCSIHardware(),
|
ValidateDiagFunc: validator.SCSIHardware(),
|
||||||
},
|
},
|
||||||
|
mkResourceVirtualEnvironmentVMHookScriptFileID: {
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Description: "A hook script",
|
||||||
|
Optional: true,
|
||||||
|
Default: dvResourceVirtualEnvironmentVMHookScript,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
CreateContext: vmCreate,
|
CreateContext: vmCreate,
|
||||||
ReadContext: vmRead,
|
ReadContext: vmRead,
|
||||||
@ -2121,6 +2130,13 @@ func vmCreateClone(ctx context.Context, d *schema.ResourceData, m interface{}) d
|
|||||||
updateBody.VGADevice = vgaDevice
|
updateBody.VGADevice = vgaDevice
|
||||||
}
|
}
|
||||||
|
|
||||||
|
hookScript := d.Get(mkResourceVirtualEnvironmentVMHookScriptFileID).(string)
|
||||||
|
if len(hookScript) > 0 {
|
||||||
|
updateBody.HookScript = &hookScript
|
||||||
|
} else {
|
||||||
|
del = append(del, "hookscript")
|
||||||
|
}
|
||||||
|
|
||||||
updateBody.Delete = del
|
updateBody.Delete = del
|
||||||
|
|
||||||
e = vmAPI.UpdateVM(ctx, updateBody)
|
e = vmAPI.UpdateVM(ctx, updateBody)
|
||||||
@ -2655,6 +2671,11 @@ func vmCreateCustom(ctx context.Context, d *schema.ResourceData, m interface{})
|
|||||||
createBody.PoolID = &poolID
|
createBody.PoolID = &poolID
|
||||||
}
|
}
|
||||||
|
|
||||||
|
hookScript := d.Get(mkResourceVirtualEnvironmentVMHookScriptFileID).(string)
|
||||||
|
if len(hookScript) > 0 {
|
||||||
|
createBody.HookScript = &hookScript
|
||||||
|
}
|
||||||
|
|
||||||
createTimeout := d.Get(mkResourceVirtualEnvironmentVMTimeoutClone).(int)
|
createTimeout := d.Get(mkResourceVirtualEnvironmentVMTimeoutClone).(int)
|
||||||
|
|
||||||
err = api.Node(nodeName).VM(0).CreateVM(ctx, createBody, createTimeout)
|
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
|
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.
|
// Update the configuration now that everything has been prepared.
|
||||||
updateBody.Delete = del
|
updateBody.Delete = del
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user