locals {
  httpSolver = {
    http01 = {
      ingress = {
        ingressClassName = "traefik"
      }
      selector = {
        dnsNames = ["mijn.365zon.nl"]
      }
    }
  }
  solvers = concat([for solver in var.extraSolvers : solver], [local.httpSolver])
}

resource "kubernetes_manifest" "clusterissuer-letsencrypt" {
  depends_on = [var.wait_on]

  manifest = {
    apiVersion = "cert-manager.io/v1"
    kind       = "ClusterIssuer"
    metadata = {
      name = "letsencrypt"
    }
    spec = {
      acme = {
        server = "https://acme-v02.api.letsencrypt.org/directory"
        email  = var.email
        privateKeySecretRef = {
          name = "letsencrypt"
        }
        solvers = local.solvers
      }
    }
  }
}

output "installed" {
  value = true
  depends_on = [kubernetes_manifest.clusterissuer-letsencrypt]
}
