diff --git a/docs/resources/virtual_environment_vm.md b/docs/resources/virtual_environment_vm.md index 2c858d88..fe97263e 100755 --- a/docs/resources/virtual_environment_vm.md +++ b/docs/resources/virtual_environment_vm.md @@ -483,7 +483,8 @@ output "ubuntu_vm_public_key" { - `wxp` - Windows XP. - `pool_id` - (Optional) The identifier for a pool to assign the virtual machine to. - `protection` - (Optional) Sets the protection flag of the VM. This will disable the remove VM and remove disk operations (defaults to `false`). -- `reboot` - (Optional) Reboot the VM after initial creation. (defaults to `false`) +- `reboot` - (Optional) Reboot the VM after initial creation (defaults to `false`). +- `reboot_after_update` - (Optional) Reboot the VM after update if needed (defaults to `true`). - `rng` - (Optional) The random number generator configuration. Can only be set by `root@pam.` - `source` - The file on the host to gather entropy from. In most cases, `/dev/urandom` should be preferred over `/dev/random` to avoid entropy-starvation issues on the host. - `max_bytes` - (Optional) Maximum bytes of entropy allowed to get injected into the guest every `period` milliseconds (defaults to `1024`). Prefer a lower value when using `/dev/random` as source. diff --git a/proxmoxtf/resource/vm/vm.go b/proxmoxtf/resource/vm/vm.go index e2464bcd..99d569ce 100644 --- a/proxmoxtf/resource/vm/vm.go +++ b/proxmoxtf/resource/vm/vm.go @@ -42,6 +42,7 @@ import ( const ( dvRebootAfterCreation = false + dvRebootAfterUpdate = true dvOnBoot = true dvACPI = true dvAgentEnabled = false @@ -144,6 +145,7 @@ const ( maxResourceVirtualEnvironmentVMNUMADevices = 8 mkRebootAfterCreation = "reboot" + mkRebootAfterUpdate = "reboot_after_update" mkOnBoot = "on_boot" mkBootOrder = "boot_order" mkACPI = "acpi" @@ -299,10 +301,16 @@ func VM() *schema.Resource { s := map[string]*schema.Schema{ mkRebootAfterCreation: { Type: schema.TypeBool, - Description: "Whether to reboot vm after creation", + Description: "Whether to reboot VM after creation", Optional: true, Default: dvRebootAfterCreation, }, + mkRebootAfterUpdate: { + Type: schema.TypeBool, + Description: "Whether to reboot VM after update if needed", + Optional: true, + Default: dvRebootAfterUpdate, + }, mkOnBoot: { Type: schema.TypeBool, Description: "Start VM on Node boot", @@ -5643,6 +5651,15 @@ func vmUpdateDiskLocationAndSize( // Perform a regular reboot in case it's necessary and haven't already been done. if reboot { + canReboot := d.Get(mkRebootAfterUpdate).(bool) + if !canReboot { + return []diag.Diagnostic{{ + Severity: diag.Warning, + Summary: "a reboot is required to apply configuration changes, but automatic " + + "reboots are disabled by 'reboot_after_update = false'. Please reboot the VM manually.", + }} + } + vmStatus, err := vmAPI.GetVMStatus(ctx) if err != nil { return diag.FromErr(err)