diff options
| author | Patrick Spek <p.spek@tyil.nl> | 2026-01-13 15:00:35 +0100 |
|---|---|---|
| committer | Patrick Spek <p.spek@tyil.nl> | 2026-01-13 15:00:35 +0100 |
| commit | cdbe424132d4e6f7951675ac5041323fae83b231 (patch) | |
| tree | a10914e32e0f6fabb1028a93f09221325ce15a57 | |
| parent | b067174006aa95656edfaa26839ada2de5242c0b (diff) | |
| download | kubernetes-container-cdbe424132d4e6f7951675ac5041323fae83b231.tar.gz kubernetes-container-cdbe424132d4e6f7951675ac5041323fae83b231.tar.bz2 | |
Add support for IngressRoute
| -rw-r--r-- | ingress_route.tf | 52 | ||||
| -rw-r--r-- | main.tf | 67 |
2 files changed, 109 insertions, 10 deletions
diff --git a/ingress_route.tf b/ingress_route.tf new file mode 100644 index 0000000..9819fcd --- /dev/null +++ b/ingress_route.tf @@ -0,0 +1,52 @@ +resource "kubernetes_manifest" "ingress_route" { + count = var.ingress_route ? 1 : 0 + + manifest = { + apiVersion = "traefik.io/v1alpha1" + kind = "IngressRoute" + + metadata = { + name = var.name + namespace = var.namespace + annotations = merge(var.annotations, var.ingress_annotations) + labels = merge(local.labels, var.labels, var.ingress_labels) + } + + spec = { + entryPoints = var.ingress_entrypoints + + routes = [ + for i, _ in var.hosts : { + match = "Host(`${var.hosts[i]}`)" + kind = "Rule" + middlewares = [ + { + name = strcontains(var.ingress_middlewares[0], "/") ? split("/", var.ingress_middlewares[0])[1] : var.ingress_middlewares[0] + namespace = strcontains(var.ingress_middlewares[0], "/") ? split("/", var.ingress_middlewares[0])[0] : var.namespace + } + ] + services = [ + { + kind = "Service" + name = kubernetes_service_v1.this[0].metadata[0].name + namespace = var.namespace + port = 0 < var.ingress_port ? var.ingress_port : var.ports[0] + } + ] + } + ] + + tls = { + certResolver = var.ingress_certresolver + secretName = var.ingress_tls_secret + + domains = [ + { + main = var.hosts[0] + sans = slice(var.hosts, 1, length(var.hosts)) + } + ] + } + } + } +} @@ -358,6 +358,16 @@ variable "ingress_annotations" { EOF } +variable "ingress_class" { + type = string + default = "" + description = <<-EOF + The name of the IngressClass to use for this Ingress object. If unset, or + set to an empty string, no Ingress object will be made. In Kubernetes + manifests, this is equivalent to `.spec.ingressClassName`. + EOF +} + variable "ingress_labels" { type = map(string) default = {} @@ -369,16 +379,6 @@ variable "ingress_labels" { EOF } -variable "ingress_class" { - type = string - default = "" - description = <<-EOF - The name of the IngressClass to use for this Ingress object. If unset, or - set to an empty string, no Ingress object will be made. In Kubernetes - manifests, this is equivalent to `.spec.ingressClassName`. - EOF -} - variable "ingress_port" { type = number default = 0 @@ -389,6 +389,53 @@ variable "ingress_port" { } # +# IngressRoute +# + +variable "ingress_certresolver" { + type = string + default = null + description = <<-EOF + The name of the certificate resolver provider. + EOF +} + +variable "ingress_entrypoints" { + type = list(string) + default = ["websecure"] + description = <<-EOF + A list of entrypoints to use with the IngressRoute object. Defaults to + `["websecure"]`. + EOF +} + +variable "ingress_middlewares" { + type = list(string) + default = [] + description = <<-EOF + A list of names of Middleware resources to apply to the IngressRoute object. + EOF +} + +variable "ingress_route" { + type = bool + default = false + description = <<-EOF + Create an IngressRoute resource, rather than an Ingress resource. Defaults + to `false`. + EOF +} + +variable "ingress_tls_secret" { + type = string + default = null + description = <<-EOF + The name of a pre-existing secret containing a TLS key and certificate for + use with TLS encryption of the connection. + EOF +} + +# # Module outputs # |
