Open
Description
What happened?
How to reproduce:
- Create individual Let's Encrypt certificates for multiple domains from list element with for_each loop with hcloud_managed_certificate and apply.
- 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"]
}
}
}