diff --git a/docs/resources/virtual_environment_vm.md b/docs/resources/virtual_environment_vm.md index b8c83d19..05e63d85 100644 --- a/docs/resources/virtual_environment_vm.md +++ b/docs/resources/virtual_environment_vm.md @@ -26,6 +26,8 @@ resource "proxmox_virtual_environment_vm" "ubuntu_vm" { # read 'Qemu guest agent' section, change to true only when ready enabled = false } + # if agent is not enabled, the VM may not be able to shutdown properly, and may need to be forced off + stop_on_destroy = true startup { order = "3" @@ -372,7 +374,6 @@ output "ubuntu_vm_public_key" { all vendor data passed to the VM via cloud-init. - `meta_data_file_id` - (Optional) The identifier for a file containing all meta data passed to the VM via cloud-init. - - `upgrade` - (Optional) Whether to do an automatic package upgrade after the first boot (defaults to `true`). - `keyboard_layout` - (Optional) The keyboard layout (defaults to `en-us`). - `da` - Danish. - `de` - German. @@ -563,7 +564,10 @@ Qemu-guest-agent is an application which can be installed inside guest VM, see Documentation](https://pve.proxmox.com/pve-docs/pve-admin-guide.html#qm_qemu_agent) For VM with `agent.enabled = false`, Proxmox uses ACPI for `Shutdown` and -`Reboot`, and `qemu-guest-agent` is not needed inside the VM. +`Reboot`, and `qemu-guest-agent` is not needed inside the VM. For some VMs, +the shutdown process may not work, causing the VM to be stuck on destroying. +Add `stop_on_destroy = true` to the VM configuration to stop the VM instead of +shutting it down. Setting `agent.enabled = true` informs Proxmox that the guest agent is expected to be *running* inside the VM. Proxmox then uses `qemu-guest-agent` instead of diff --git a/fwprovider/tests/resource_vm_test.go b/fwprovider/tests/resource_vm_test.go index 3ccd8ec0..b4e9f502 100644 --- a/fwprovider/tests/resource_vm_test.go +++ b/fwprovider/tests/resource_vm_test.go @@ -261,52 +261,6 @@ func TestAccResourceVMInitialization(t *testing.T) { }), ), }}}, - {"cloud-init: clone", []resource.TestStep{{ - Config: te.renderConfig(` - resource "proxmox_virtual_environment_vm" "test_vm_cloudinit_template" { - node_name = "{{.NodeName}}" - name = "test-vm-cloudinit-template" - started = false - template = "true" - initialization { - upgrade = false - } - } - resource "proxmox_virtual_environment_file" "cloud_config" { - content_type = "snippets" - datastore_id = "local" - node_name = "{{.NodeName}}" - source_raw { - data = <<-EOF - #cloud-config - runcmd: - - apt update - - apt install -y qemu-guest-agent - - systemctl enable qemu-guest-agent - - systemctl start qemu-guest-agent - EOF - file_name = "cloud-config.yaml" - } - } - resource "proxmox_virtual_environment_vm" "test_vm_cloudinit" { - node_name = "{{.NodeName}}" - name = "test-vm-cloudinit" - started = false - description = "Example to cause ciupgrade issue" - clone { - vm_id = proxmox_virtual_environment_vm.test_vm_cloudinit_template.id - } - - initialization { - user_data_file_id = proxmox_virtual_environment_file.cloud_config.id - } - }`), - Check: resource.ComposeTestCheckFunc( - testResourceAttributes("proxmox_virtual_environment_vm.test_vm_cloudinit", map[string]string{ - "initialization.0.upgrade": "false", - }), - ), - }}}, } for _, tt := range tests { diff --git a/proxmox/nodes/vms/vms_types.go b/proxmox/nodes/vms/vms_types.go index ca45aed2..fc9d6b81 100644 --- a/proxmox/nodes/vms/vms_types.go +++ b/proxmox/nodes/vms/vms_types.go @@ -50,8 +50,9 @@ type CustomCloudInitConfig struct { SearchDomain *string `json:"searchdomain,omitempty" url:"searchdomain,omitempty"` SSHKeys *CustomCloudInitSSHKeys `json:"sshkeys,omitempty" url:"sshkeys,omitempty"` Type *string `json:"citype,omitempty" url:"citype,omitempty"` - Upgrade *types.CustomBool `json:"ciupgrade,omitempty" url:"ciupgrade,omitempty,int"` - Username *string `json:"ciuser,omitempty" url:"ciuser,omitempty"` + // Can't be reliably set, it is TRUE by default in PVE + // Upgrade *types.CustomBool `json:"ciupgrade,omitempty" url:"ciupgrade,omitempty,int"` + Username *string `json:"ciuser,omitempty" url:"ciuser,omitempty"` } // CustomCloudInitFiles handles QEMU cloud-init custom files parameters. @@ -825,14 +826,6 @@ func (r CustomCloudInitConfig) EncodeValues(_ string, v *url.Values) error { v.Add("citype", *r.Type) } - if r.Upgrade != nil { - if *r.Upgrade { - v.Add("ciupgrade", "1") - } else { - v.Add("ciupgrade", "0") - } - } - if r.Username != nil { v.Add("ciuser", *r.Username) } diff --git a/proxmoxtf/resource/vm/vm.go b/proxmoxtf/resource/vm/vm.go index 5fd93496..bebf2c5f 100644 --- a/proxmoxtf/resource/vm/vm.go +++ b/proxmoxtf/resource/vm/vm.go @@ -904,6 +904,7 @@ func VM() *schema.Resource { Description: "Whether to do an automatic package upgrade after the first boot", Optional: true, Computed: true, + Deprecated: "The `upgrade` attribute is deprecated and will be removed in a future release.", }, }, }, @@ -2973,11 +2974,6 @@ func vmGetCloudInitConfig(d *schema.ResourceData) *vms.CustomCloudInitConfig { initializationConfig.Type = &initializationType } - if initializationBlock[mkInitializationUpgrade] != nil && initializationConfig.Files == nil { - v := types.CustomBool(initializationBlock[mkInitializationUpgrade].(bool)) - initializationConfig.Upgrade = &v - } - return initializationConfig } @@ -4135,12 +4131,6 @@ func vmReadCustom( initialization[mkInitializationType] = "" } - if vmConfig.CloudInitUpgrade != nil { - initialization[mkInitializationUpgrade] = *vmConfig.CloudInitUpgrade - } else if len(initialization) > 0 { - initialization[mkInitializationUpgrade] = dvInitializationUpgrade - } - currentInitialization := d.Get(mkInitialization).([]interface{}) //nolint:gocritic