Skip to content

[Bug]: Error "certificate still in use" when removing domain name from hcloud_managed_certificate #1141

Open
@martipoe

Description

@martipoe

What happened?

How to reproduce:

  1. Create individual Let's Encrypt certificates for multiple domains from list element with for_each loop with hcloud_managed_certificate and apply.
  2. Remove a domain from the list element and apply - fails on error Error: certificate still in use

What did you expect to happen?

The certificate for the no longer needed domain should be removed without errors.

Please provide a minimal working example

locals {
  domain_list = compact(flatten([var.base_url, var.release_url, split(" ", var.multisite_urls)]))
}
# Generate a certificate for each domain individually
resource "hcloud_managed_certificate" "managed_cert" {
  for_each     = toset(local.domain_list)
  name         = replace(each.value, ".", "-")
  domain_names = [each.value]
  labels       = {}
}

resource "hcloud_load_balancer_service" "load_balancer_service" {
  load_balancer_id = hcloud_load_balancer.lb01.id
  protocol         = "https"
  listen_port      = "443"
  destination_port = "80"

  http {
    certificates    = [for cert in hcloud_managed_certificate.managed_cert : cert.id]
    redirect_http   = true
    sticky_sessions = true
    cookie_name     = "HCLBSTICKY"
    cookie_lifetime = 300
  }

  health_check {
    protocol = "http"
    port     = 80
    interval = 10
    timeout  = 5

    http {
      domain       = var.base_url
      path         = "/"
      status_codes = ["200", "404"]
    }
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions