variable "app_name" { type = string } variable "match_route" { type = string } variable "app_port" { type = number default = 80 } variable "app_port_name" { type = string default = "http" } variable "entrypoints" { type = list(string) default = [ "web", "websecure", ] } variable "namespace" { type = string default = "default" } locals { service_name = "${var.app_name}-service" ingress_name = "${var.app_name}-ingress" } resource "kubernetes_service" "traefik-ingress-service" { metadata { name = local.service_name } spec { selector = { app = var.app_name } port { name = var.app_port_name port = var.app_port } } } resource "kubernetes_manifest" "traefik-ingress-route" { manifest = { apiVersion = "traefik.containo.us/v1alpha1" kind = "IngressRoute" metadata = { name = local.ingress_name namespace = var.namespace } spec = { entryPoints = var.entrypoints routes = [ { match = var.match_route kind = "Rule" services = [ { kind = "Service" name = local.service_name port = var.app_port }, ] }, ] } } } output "service_name" { value = local.service_name } output "ingress_name" { value = local.ingress_name }