Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

terraform destroy with enabled protection mode causes VM to shutdown #1043

Open
maksimsamt opened this issue Jun 12, 2024 · 4 comments
Open
Labels
issue/not-a-bug The reported issue is the intended behavior or the problem is not inside this project resource/qemu Issue or PR related to Qemu resource

Comments

@maksimsamt
Copy link
Contributor

maksimsamt commented Jun 12, 2024

System details:

  • Proxmox VE 8.2.2
  • Terraform v1.8.4
  • terraform-provider-proxmox v3.0.1-rc3

As per documentation:

protection: Enable/disable the VM protection from being removed. The default value of false indicates the VM is removable.

Setting this value to true and running terraform destroy gives the following result:

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  - destroy

Terraform will perform the following actions:

  # proxmox_vm_qemu.cloud_vm_from_packer_template will be destroyed
  - resource "proxmox_vm_qemu" "cloud_vm_from_packer_template" {

  ...
        - protection             = true -> null
  ...
  
Plan: 0 to add, 0 to change, 1 to destroy.

Do you really want to destroy all resources?
  Terraform will destroy all your managed infrastructure, as shown above.
  There is no undo. Only 'yes' will be accepted to confirm.

  Enter a value: yes


proxmox_vm_qemu.cloud_vm_from_packer_template: Destroying... [id=***/qemu/***]
╷
│ Error: 500 can't remove VM *** - protection mode enabled

Everything looks fine, but this action causes VM to shutdown.

I expected that in protection mode VM state would remain untouched, for example, keeps running.

The second thing, is protection argument redundant? (resolved, not redundant, answer #1043 (comment))

Cause that protection from destroy can be achieved using Terraform built-in lifecycle meta-argument, for example:

...
resource "proxmox_vm_qemu" "cloud_vm_from_packer_template" {
...
  # https://developer.hashicorp.com/terraform/language/meta-arguments/lifecycle
  lifecycle {
    prevent_destroy = true
  }
...
}
...

In this case gives such result:

│ Error: Instance cannot be destroyed
│ 
│   on main.tf line 42:
│   42: resource "proxmox_vm_qemu" "cloud_vm_from_packer_template" {
│ 
│ Resource proxmox_vm_qemu.cloud_vm_from_packer_template has lifecycle.prevent_destroy set, but the plan calls for this resource to be destroyed. To avoid this error and continue with the plan, either disable lifecycle.prevent_destroy or reduce the scope of the
│ plan using the -target option.
@Tinyblargon
Copy link
Collaborator

@maksimsamt The protection is about the protection flag in proxmox. That you can't delete it with it enabled is a known issue Telmate/proxmox-api-go#330

@maksimsamt
Copy link
Contributor Author

@Tinyblargon,

The protection is about the protection flag in proxmox

Thanks, got it.

That you can't delete it with it enabled is a known issue

Isn't this expected behavior? This is exactly the behavior I expect...

But what about this?

Everything looks fine, but this action causes VM to shutdown.
I expected that in protection mode VM state would remain untouched, for example, keeps running.

@maksimsamt maksimsamt changed the title terraform destroy with enabled protection mode causes VM to shutdown. Is protection argument redundant? terraform destroy with enabled protection mode causes VM to shutdown Jun 12, 2024
Copy link

This issue is stale because it has been open for 60 days with no activity. Please update the provider to the latest version and, in the issue persist, provide full configuration and debug logs

@maksimsamt
Copy link
Contributor Author

still actual:

Everything looks fine, but this action causes VM to shutdown.
I expected that in protection mode VM state would remain untouched, for example, keeps running.

@Tinyblargon Tinyblargon added issue/not-a-bug The reported issue is the intended behavior or the problem is not inside this project resource/qemu Issue or PR related to Qemu resource and removed type/bug labels Nov 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
issue/not-a-bug The reported issue is the intended behavior or the problem is not inside this project resource/qemu Issue or PR related to Qemu resource
Projects
None yet
Development

No branches or pull requests

2 participants