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_certificate always gets updated when a certificate chain is used #1110

Open
julego opened this issue Mar 10, 2024 · 1 comment
Labels
🐛 bug Something isn't working

Comments

@julego
Copy link

julego commented Mar 10, 2024

Describe the bug
When a certificate chain is used, changes are always detected on a proxmox_virtual_environment_certificate resource when running terraform plan, and then gets updated on each terraform apply, even when the certificate chain was previously successfully installed on the node.

This happens probably because the Proxmox API endpoint (/nodes/{node}/certificates/info) only returns the first certificate found in /etc/pve/nodes/{node}/pveproxy-ssl.pem, not the whole file/chain content.

A workaround would be to use the SSH client to get the actual chain content.

To Reproduce
Steps to reproduce the behavior:

  1. Create a proxmox_virtual_environment_certificate resource with a certificate chain
resource "proxmox_virtual_environment_certificate" "pve" {
  node_name = "pve"

  certificate = "pem encoded certificate"
  certificate_chain = "pem encoded intermediate certificate"
  private_key = "pem encoded private key"
}
  1. Run terraform apply to initially install the certificate

  2. Confirm that the pveproxy-ssl.pem file installed on the node contains the whole chain

root@pve:~# cat /etc/pve/nodes/pve/pveproxy-ssl.pem
-----BEGIN CERTIFICATE-----
[certificate]
-----END CERTIFICATE-----
-----BEGIN CERTIFICATE-----
[intermediate]
-----END CERTIFICATE-----
  1. Run terraform apply again, the certificate gets re-installed on the node
proxmox_virtual_environment_certificate.pve: Refreshing state... [id=pve_certificate]

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  ~ update in-place

Terraform will perform the following actions:

  # proxmox_virtual_environment_certificate.pve will be updated in-place
  ~ resource "proxmox_virtual_environment_certificate" "pve" {
      + certificate_chain         = <<-EOT
            -----BEGIN CERTIFICATE-----
            [...]
            -----END CERTIFICATE-----
        EOT
        id                        = "pve_certificate"
        # (13 unchanged attributes hidden)
    }

Plan: 0 to add, 1 to change, 0 to destroy.
proxmox_virtual_environment_certificate.pve: Modifying... [id=pve_certificate]
proxmox_virtual_environment_certificate.pve: Modifications complete after 1s [id=pve_certificate]

Apply complete! Resources: 0 added, 1 changed, 0 destroyed.

Expected behavior
Running terraform plan should not detect any changes, and terraform apply should not reinstall the certificate.

Additional context
Tested with Terraform 1.5 and provider 0.48.2 on a single node setup running Proxmox 8.1.4

@julego julego added the 🐛 bug Something isn't working label Mar 10, 2024
@spacex
Copy link

spacex commented Mar 11, 2024

This is partially due to the fact that the proxmox API does not include the certificate chain in the response.

It should be possible for the resource to "remember" what certificate chain it set on the resource and update it when presented with a new one.

Also, a workaround is to use this in the resource:

  lifecycle {
    ignore_changes = [
      certificate_chain
    ]
  }

This causes it to not show as changed on subsequent plans/applies, however, if the chain changed and the certificate didn't (for some reason, which could even include adding a missing intermediate CA), it wouldn't trigger an update.

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

No branches or pull requests

2 participants