91 lines
2.5 KiB
HCL
91 lines
2.5 KiB
HCL
|
|
locals {
|
|
app_slug = "${var.instance}${var.component == "" ? "" : "-"}${var.component}"
|
|
pres_labels = merge(var.labels, {
|
|
"app.kubernetes.io/component" = "presentation"
|
|
})
|
|
rules = [for v in var.dns_names : {
|
|
"host" = "${v}"
|
|
"http" = {
|
|
"paths" = [for mapper in var.services_mapping : {
|
|
"path" = "/${mapper.path}"
|
|
"pathType" = "Prefix"
|
|
"backend" = {
|
|
"service" = mapper.service
|
|
}
|
|
}]
|
|
}
|
|
}]
|
|
secret_name = var.cert_name != "" ? var.cert_name : "${local.app_slug}-cert"
|
|
tls = var.entrypoint == "" || length(regexall(".*websecure.*", var.entrypoint)) > 0 ? [
|
|
{
|
|
secretName = local.secret_name
|
|
hosts = var.dns_names
|
|
}
|
|
] : []
|
|
middlewares = concat(
|
|
var.create_redirect ? ["${local.app_slug}-https"] : [],
|
|
var.middlewares
|
|
)
|
|
annotations = merge(
|
|
var.entrypoint != "" ? {
|
|
"traefik.ingress.kubernetes.io/router.entrypoints" = var.entrypoint
|
|
} : {},
|
|
length(local.middlewares) > 0 ? {
|
|
"traefik.ingress.kubernetes.io/router.middlewares" : "${join(",", [for m in local.middlewares : format("%s-%s@kubernetescrd", var.namespace, m)])}"
|
|
} : {},
|
|
)
|
|
}
|
|
|
|
resource "kubectl_manifest" "certificate" {
|
|
count = var.cert_name == "" ? 1 : 0
|
|
yaml_body = <<-EOF
|
|
apiVersion: "cert-manager.io/v1"
|
|
kind: "Certificate"
|
|
metadata:
|
|
name: "${local.app_slug}"
|
|
namespace: "${var.namespace}"
|
|
labels: ${jsonencode(local.pres_labels)}
|
|
spec:
|
|
secretName: "${local.secret_name}"
|
|
dnsNames: ${jsonencode(var.dns_names)}
|
|
issuerRef:
|
|
kind: "ClusterIssuer"
|
|
name: "${var.issuer}"
|
|
group: "cert-manager.io"
|
|
EOF
|
|
}
|
|
|
|
resource "kubectl_manifest" "https_redirect" {
|
|
count = var.create_redirect ? 1 : 0
|
|
yaml_body = <<-EOF
|
|
apiVersion: "traefik.io/v1alpha1"
|
|
kind: "Middleware"
|
|
metadata:
|
|
name: "${local.app_slug}-https"
|
|
namespace: "${var.namespace}"
|
|
labels: ${jsonencode(local.pres_labels)}
|
|
spec:
|
|
redirectScheme:
|
|
scheme: "https"
|
|
permanent: true
|
|
EOF
|
|
}
|
|
|
|
resource "kubectl_manifest" "ingress" {
|
|
force_conflicts = true
|
|
yaml_body = <<-EOF
|
|
apiVersion: "networking.k8s.io/v1"
|
|
kind: "Ingress"
|
|
metadata:
|
|
name: "${local.app_slug}"
|
|
namespace: "${var.namespace}"
|
|
labels: ${jsonencode(local.pres_labels)}
|
|
annotations: ${jsonencode(local.annotations)}
|
|
spec:
|
|
ingressClassName: "${var.ingress_class}"
|
|
rules: ${jsonencode(local.rules)}
|
|
tls: ${jsonencode(local.tls)}
|
|
EOF
|
|
}
|