ingress module
This commit is contained in:
+43
-16
@@ -59,7 +59,9 @@ variable "kubernetes_input" {
|
||||
|
||||
|
||||
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 }
|
||||
|
||||
metadata {
|
||||
name = "${each.key}-ingress"
|
||||
namespace = coalesce(each.value.namespace, each.value.connected_namespace, each.key)
|
||||
@@ -72,14 +74,23 @@ resource "kubernetes_ingress_v1" "automatic_ingress" {
|
||||
|
||||
spec {
|
||||
ingress_class_name = "traefik"
|
||||
# Dynamic TLS configuration for cert-manager
|
||||
tls {
|
||||
hosts = [join(".", [coalesce(each.value.domain_name, each.key), "geeraert.eu"])]
|
||||
secret_name = "${each.key}-tls-secret" # cert-manager will create and manage this secret automatically
|
||||
|
||||
# --- DYNAMIC TLS BLOCK ---
|
||||
# Generates a separate TLS block + secret per domain entry
|
||||
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 {
|
||||
host = join(".", [coalesce(each.value.domain_name, each.key), "geeraert.eu"])
|
||||
# --- DYNAMIC RULE BLOCK ---
|
||||
# Loops through the domain list and creates an HTTP path routing rule for each
|
||||
dynamic "rule" {
|
||||
for_each = toset(coalesce(each.value.domain_name, [each.key]))
|
||||
content {
|
||||
host = join(".", [rule.value, "geeraert.eu"])
|
||||
http {
|
||||
path {
|
||||
path = "/"
|
||||
@@ -87,7 +98,7 @@ resource "kubernetes_ingress_v1" "automatic_ingress" {
|
||||
service {
|
||||
name = "${each.key}-svc"
|
||||
port {
|
||||
number = each.value.service_port[0] #selecting the first of the list
|
||||
number = each.value.service_port[0]
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -95,11 +106,16 @@ resource "kubernetes_ingress_v1" "automatic_ingress" {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
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 {
|
||||
name = "${each.key}-ingress-legacy"
|
||||
name = "${each.key}-ingress"
|
||||
namespace = coalesce(each.value.namespace, each.value.connected_namespace, each.key)
|
||||
|
||||
annotations = {
|
||||
@@ -110,14 +126,23 @@ resource "kubernetes_ingress_v1" "automatic_ingress_legacy" {
|
||||
|
||||
spec {
|
||||
ingress_class_name = "traefik"
|
||||
# Dynamic TLS configuration for cert-manager
|
||||
tls {
|
||||
hosts = [join(".", [coalesce(each.value.domain_name, each.key), "tryton.geeraert.eu"])]
|
||||
secret_name = "${each.key}-tryton-tls-secret" # cert-manager will create and manage this secret automatically
|
||||
|
||||
# --- DYNAMIC TLS BLOCK ---
|
||||
# Generates a separate TLS block + secret per domain entry
|
||||
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 {
|
||||
host = join(".", [coalesce(each.value.domain_name, each.key), "tryton.geeraert.eu"])
|
||||
# --- DYNAMIC RULE BLOCK ---
|
||||
# Loops through the domain list and creates an HTTP path routing rule for each
|
||||
dynamic "rule" {
|
||||
for_each = toset(coalesce(each.value.domain_name, [each.key]))
|
||||
content {
|
||||
host = join(".", [rule.value, "geeraert.eu"])
|
||||
http {
|
||||
path {
|
||||
path = "/"
|
||||
@@ -125,7 +150,7 @@ resource "kubernetes_ingress_v1" "automatic_ingress_legacy" {
|
||||
service {
|
||||
name = "${each.key}-svc"
|
||||
port {
|
||||
number = each.value.service_port[0] #selecting the first of the list
|
||||
number = each.value.service_port[0]
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -133,4 +158,6 @@ resource "kubernetes_ingress_v1" "automatic_ingress_legacy" {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user