Optimize service port definition
This commit is contained in:
@@ -4,23 +4,22 @@ locals {
|
||||
pres_labels = merge(var.labels, {
|
||||
"app.kubernetes.io/component" = "presentation"
|
||||
})
|
||||
rules = [for v in var.dns_names : {
|
||||
"host" = "${v}"
|
||||
rules = [for rule in var.rules_mapper : {
|
||||
"host" = rule.host
|
||||
"http" = {
|
||||
"paths" = [for mapper in var.services_mapping : {
|
||||
"paths" = [for mapper in rule.paths : {
|
||||
"path" = "/${mapper.path}"
|
||||
"pathType" = "Prefix"
|
||||
"backend" = {
|
||||
"service" = mapper.service
|
||||
}
|
||||
"pathType" = mapper.type != null && mapper.type != "" ? mapper.type : "Prefix"
|
||||
"backend" = mapper.backend
|
||||
}]
|
||||
}
|
||||
}]
|
||||
dns_names = [for rule in var.rules_mapper : rule.host]
|
||||
secret_name = var.cert_name != "" ? var.cert_name : "${local.app_slug}-cert"
|
||||
tls = var.entrypoint == "" || length(regexall(".*websecure.*", var.entrypoint)) > 0 ? [
|
||||
{
|
||||
secretName = local.secret_name
|
||||
hosts = var.dns_names
|
||||
hosts = local.dns_names
|
||||
}
|
||||
] : []
|
||||
middlewares = concat(
|
||||
@@ -48,7 +47,7 @@ resource "kubectl_manifest" "certificate" {
|
||||
labels: ${jsonencode(local.pres_labels)}
|
||||
spec:
|
||||
secretName: "${local.secret_name}"
|
||||
dnsNames: ${jsonencode(var.dns_names)}
|
||||
dnsNames: ${jsonencode(local.dns_names)}
|
||||
issuerRef:
|
||||
kind: "ClusterIssuer"
|
||||
name: "${var.issuer}"
|
||||
|
||||
@@ -17,24 +17,28 @@ variable "ingress_class" {
|
||||
variable "labels" {
|
||||
type = map(string)
|
||||
}
|
||||
variable "dns_names" {
|
||||
type = list(string)
|
||||
}
|
||||
variable "middlewares" {
|
||||
type = list(string)
|
||||
default = []
|
||||
}
|
||||
|
||||
variable "services_mapping" {
|
||||
variable "rules_mapper" {
|
||||
type = list(object({
|
||||
path = optional(string)
|
||||
service = object({
|
||||
name= string
|
||||
port = object({
|
||||
number = number
|
||||
host = string
|
||||
paths = list(object({
|
||||
path = optional(string)
|
||||
type = optional(string)
|
||||
backend = object({
|
||||
service = object({
|
||||
name = string
|
||||
port = object({
|
||||
name = string
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
}))
|
||||
}))
|
||||
description = "Simplified rules mapper for ingress"
|
||||
}
|
||||
|
||||
variable "entrypoint" {
|
||||
|
||||
Reference in New Issue
Block a user