ingress module

This commit is contained in:
pierre.geeraert
2026-10-13 17:29:57 +01:00
parent c158dffcc9
commit e80f53c2e5
4 changed files with 139 additions and 93 deletions
-5
View File
@@ -1,8 +1,3 @@
module "import_output" {
source = "../modules"
hello = "coucou"
}
resource "helm_release" "cert_manager" {
name = "cert-manager"
repository = "oci://quay.io"
+3 -74
View File
@@ -1,79 +1,8 @@
resource "kubernetes_ingress_v1" "automatic_ingress" {
for_each = { for key, value in var.kubernetes : 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)
annotations = {
"cert-manager.io/cluster-issuer" = "letsencrypt-prod"
"traefik.ingress.kubernetes.io/router.entrypoints" = "websecure"
}
module "ingress" {
source = "../modules/ingress"
kubernetes_input = var.kubernetes
}
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
}
rule {
host = join(".", [coalesce(each.value.domain_name, each.key), "geeraert.eu"])
http {
path {
path = "/"
backend {
service {
name = "${each.key}-svc"
port {
number = each.value.service_port[0] #selecting the first of the list
}
}
}
}
}
}
}
}
resource "kubernetes_ingress_v1" "automatic_ingress_legacy" {
for_each = { for key, value in var.kubernetes : key => value if value.service_port != null && value.enabled == true && value.docker != true && value.exposed == true && value.legacy_domain == true }
metadata {
name = "${each.key}-ingress-legacy"
namespace = coalesce(each.value.namespace, each.value.connected_namespace, each.key)
annotations = {
"cert-manager.io/cluster-issuer" = "letsencrypt-prod"
"traefik.ingress.kubernetes.io/router.entrypoints" = "websecure"
}
}
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
}
rule {
host = join(".", [coalesce(each.value.domain_name, each.key), "tryton.geeraert.eu"])
http {
path {
path = "/"
backend {
service {
name = "${each.key}-svc"
port {
number = each.value.service_port[0] #selecting the first of the list
}
}
}
}
}
}
}
}
resource "kubernetes_service_v1" "automatic_service" {
for_each = { for key, value in var.kubernetes : key => value if value.service_port != null && value.enabled == true && value.docker != true }
-14
View File
@@ -1,14 +0,0 @@
variable "hello" {
type = string
}
output "instance_id" {
description = "ID of the EC2 instance"
value = var.hello
}
resource "null_resource" "test_module_linkage" {
triggers = {
passed_value = var.hello
}
}
+136
View File
@@ -0,0 +1,136 @@
variable "kubernetes_input" {
type = map(object({
name = optional(string)
docker = optional(bool)
image = string
pvc = optional(map(object({
name = optional(string)
config_map = optional(bool, false)
secret = optional(bool, false)
local_path = optional(bool, false)
host_path = optional(string)
storage_class_name = optional(string, "nfs-storage-intelligent")
annotations_fileType = optional(string)
mount_path = string
sub_path = optional(string)
})))
environment = optional(map(object({
name = optional(string)
value = optional(string)
value_from = optional(object({
secret_key_ref = object({
name = string
key = optional(string, null)
})
}))
})))
replicas = optional(number, 1)
namespace = optional(string)
connected_namespace = optional(string, "")
command = optional(list(string))
service_port = optional(list(number))
external_port = optional(bool, false)
service_type = optional(string, "ClusterIP")
service_name = optional(string)
domain_name = optional(string)
legacy_domain = optional(bool, false)
exposed = optional(bool, true)
liveness_tcp_socket = optional(number)
liveness_http_get = optional(string)
liveness_http_get_path = optional(string)
database = optional(map(string))
database_command = optional(list(string))
database_args = optional(list(string))
redis = optional(map(string))
enabled = optional(bool, true)
secret_ref = optional(list(string))
config_map_ref = optional(list(string))
config_map_import = optional(list(string))
secret_import = optional(list(string))
extra_manifest = optional(list(string))
requirements = optional(map(string))
dns_nameservers = optional(string)
service_account_name = optional(string)
environment_variables = optional(map(string), { name = "value" })
security_context = optional(bool, false)
}))
}
resource "kubernetes_ingress_v1" "automatic_ingress" {
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)
annotations = {
"cert-manager.io/cluster-issuer" = "letsencrypt-prod"
"traefik.ingress.kubernetes.io/router.entrypoints" = "websecure"
}
}
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
}
rule {
host = join(".", [coalesce(each.value.domain_name, each.key), "geeraert.eu"])
http {
path {
path = "/"
backend {
service {
name = "${each.key}-svc"
port {
number = each.value.service_port[0] #selecting the first of the list
}
}
}
}
}
}
}
}
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 }
metadata {
name = "${each.key}-ingress-legacy"
namespace = coalesce(each.value.namespace, each.value.connected_namespace, each.key)
annotations = {
"cert-manager.io/cluster-issuer" = "letsencrypt-prod"
"traefik.ingress.kubernetes.io/router.entrypoints" = "websecure"
}
}
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
}
rule {
host = join(".", [coalesce(each.value.domain_name, each.key), "tryton.geeraert.eu"])
http {
path {
path = "/"
backend {
service {
name = "${each.key}-svc"
port {
number = each.value.service_port[0] #selecting the first of the list
}
}
}
}
}
}
}
}