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

proxmox_virtual_environment_vm forces replacement by unchanged initialization.user_account.keys #1443

Open
charles-low opened this issue Jul 15, 2024 · 2 comments
Labels
🐛 bug Something isn't working 🤷 can't reproduce

Comments

@charles-low
Copy link

charles-low commented Jul 15, 2024

Describe the bug
The terraform reported that the vm required to be replaced because the initialization.user_account.keys has changed.
However the key didn't change, the terraform plan shows the following output

          ~ user_account {
              ~ keys     = [ # forces replacement
                  - "ssh-ed25519 AAAACbla bla bla bla",
                  + <<-EOT
                        ssh-ed25519 AAAACbla bla bla bla
                    EOT,
                ]
              ~ password = (sensitive value)
                # (1 unchanged attribute hidden)
            }

To Reproduce

  1. Create a vm with initialization block that include user_account and ssh pubkey in an array.
  2. Apply twice, the second time will state that the vm need to be replaced due to the keys is different.

Please also provide a minimal Terraform configuration that reproduces the issue.

resource "proxmox_virtual_environment_vm" "elasticsearch" {
    for_each = local.instances

    name                    = each.value.name
    pool_id                 = each.value.pool_id
    node_name               = each.value.node_name
    description             = "Managed by Terraform - ElasticSearch 01"
    tags                    = ["elasticsearch","terraform","ubuntu","24.04","cloud-init"]


        user_account {
          username = "admin"
          password = random_password.passwords[each.key].bcrypt_hash
          keys = [ file("~/.ssh/id_ed25519.pub") ]
       }
}

Expected behavior
The vm should stay intact.

@charles-low charles-low added the 🐛 bug Something isn't working label Jul 15, 2024
@bpg
Copy link
Owner

bpg commented Jul 16, 2024

Hi @charles-low 👋🏼

I can't reproduce the issue with this template:

resource "proxmox_virtual_environment_vm" "test_vm_cloudinit" {
    node_name = "pve"
    started   = false
    agent {
        enabled = true
    }
    cpu {
        cores = 2
    }
    memory {
        dedicated = 2048
    }
    disk {
        datastore_id = "local-lvm"
        file_id      = proxmox_virtual_environment_download_file.ubuntu_cloud_image.id
        interface    = "virtio0"
        iothread     = true
        discard      = "on"
        size         = 20
    }

    initialization {
        user_account {
            username = "ubuntu"
            keys     = [
                "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOQCHPhOV9XsJa3uq4bmKymklNy6ktgBB/+2umizgnnY",
            ]
        }
        ip_config {
            ipv4 {
                address = "dhcp"
            }
        }
    }
    network_device {
        bridge = "vmbr0"
    }
}

It looks like the key in your case has changed from a single line to a heredoc-style with leading spaces:

<<-EOT
    ssh-ed25519 AAAACbla bla bla bla
EOT,

From Terraform's perspective, this is a value change, even though the significant string has not changed.

@bpg
Copy link
Owner

bpg commented Jul 30, 2024

Hi @charles-low 👋🏼

It looks like the key in your case has changed from a single line to a heredoc-style with leading space

Have you had a chance to double check that? Is your issue still reproducible?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Something isn't working 🤷 can't reproduce
Projects
None yet
Development

No branches or pull requests

2 participants