ingress module

This commit is contained in:
pierre.geeraert
2026-10-13 18:00:23 +01:00
parent 243bd3a998
commit 8002d9d0b7
+57 -30
View File
@@ -59,7 +59,9 @@ variable "kubernetes_input" {
resource "kubernetes_ingress_v1" "automatic_ingress" { resource "kubernetes_ingress_v1" "automatic_ingress" {
# Keep your top-level filter for filtering active services
for_each = { for key, value in var.kubernetes_input : key => value if value.service_port != null && value.enabled == true && value.docker != true && value.exposed == true } for_each = { for key, value in var.kubernetes_input : key => value if value.service_port != null && value.enabled == true && value.docker != true && value.exposed == true }
metadata { metadata {
name = "${each.key}-ingress" name = "${each.key}-ingress"
namespace = coalesce(each.value.namespace, each.value.connected_namespace, each.key) namespace = coalesce(each.value.namespace, each.value.connected_namespace, each.key)
@@ -72,34 +74,48 @@ resource "kubernetes_ingress_v1" "automatic_ingress" {
spec { spec {
ingress_class_name = "traefik" ingress_class_name = "traefik"
# Dynamic TLS configuration for cert-manager
tls { # --- DYNAMIC TLS BLOCK ---
hosts = [join(".", [coalesce(each.value.domain_name, each.key), "geeraert.eu"])] # Generates a separate TLS block + secret per domain entry
secret_name = "${each.key}-tls-secret" # cert-manager will create and manage this secret automatically dynamic "tls" {
for_each = toset(coalesce(each.value.domain_name, [each.key]))
content {
hosts = [join(".", [tls.value, "geeraert.eu"])]
secret_name = "${each.key}-${tls.value}-tls-secret"
}
} }
rule { # --- DYNAMIC RULE BLOCK ---
host = join(".", [coalesce(each.value.domain_name, each.key), "geeraert.eu"]) # Loops through the domain list and creates an HTTP path routing rule for each
http { dynamic "rule" {
path { for_each = toset(coalesce(each.value.domain_name, [each.key]))
path = "/" content {
backend { host = join(".", [rule.value, "geeraert.eu"])
service { http {
name = "${each.key}-svc" path {
port { path = "/"
number = each.value.service_port[0] #selecting the first of the list backend {
service {
name = "${each.key}-svc"
port {
number = each.value.service_port[0]
}
} }
} }
} }
} }
} }
} }
} }
} }
resource "kubernetes_ingress_v1" "automatic_ingress_legacy" { resource "kubernetes_ingress_v1" "automatic_ingress_legacy" {
for_each = { for key, value in var.kubernetes_input : key => value if value.service_port != null && value.enabled == true && value.docker != true && value.exposed == true && value.legacy_domain == true } # Keep your top-level filter for filtering active services
for_each = { for key, value in var.kubernetes_input : key => value if value.service_port != null && value.enabled == true && value.docker != true && value.exposed == true }
metadata { metadata {
name = "${each.key}-ingress-legacy" name = "${each.key}-ingress"
namespace = coalesce(each.value.namespace, each.value.connected_namespace, each.key) namespace = coalesce(each.value.namespace, each.value.connected_namespace, each.key)
annotations = { annotations = {
@@ -110,27 +126,38 @@ resource "kubernetes_ingress_v1" "automatic_ingress_legacy" {
spec { spec {
ingress_class_name = "traefik" ingress_class_name = "traefik"
# Dynamic TLS configuration for cert-manager
tls { # --- DYNAMIC TLS BLOCK ---
hosts = [join(".", [coalesce(each.value.domain_name, each.key), "tryton.geeraert.eu"])] # Generates a separate TLS block + secret per domain entry
secret_name = "${each.key}-tryton-tls-secret" # cert-manager will create and manage this secret automatically dynamic "tls" {
for_each = toset(coalesce(each.value.domain_name, [each.key]))
content {
hosts = [join(".", [tls.value, "geeraert.eu"])]
secret_name = "${each.key}-${tls.value}-tls-secret"
}
} }
rule { # --- DYNAMIC RULE BLOCK ---
host = join(".", [coalesce(each.value.domain_name, each.key), "tryton.geeraert.eu"]) # Loops through the domain list and creates an HTTP path routing rule for each
http { dynamic "rule" {
path { for_each = toset(coalesce(each.value.domain_name, [each.key]))
path = "/" content {
backend { host = join(".", [rule.value, "geeraert.eu"])
service { http {
name = "${each.key}-svc" path {
port { path = "/"
number = each.value.service_port[0] #selecting the first of the list backend {
service {
name = "${each.key}-svc"
port {
number = each.value.service_port[0]
}
} }
} }
} }
} }
} }
} }
} }
} }