Refacto and add modules
This commit is contained in:
@@ -13,9 +13,10 @@ locals {
|
||||
"protocol" = var.protocols[idx]
|
||||
"targetPort" = var.ports[idx]
|
||||
}] : []
|
||||
lb_ports = var.svc_type == "LoadBalancer" ? [for idx, port in var.lb_ports : {
|
||||
"port" = port
|
||||
"targetPort" = var.ports[idx]
|
||||
lb_ports = var.svc_type == "LoadBalancer" ? [for port in var.lb_ports : {
|
||||
"port" = port.port.number
|
||||
"name" = port.name
|
||||
"targetPort" = port.port.number
|
||||
}] : []
|
||||
node_ports = var.svc_type == "NodePort" ? [for idx, port in var.ports : {
|
||||
"port" = port
|
||||
@@ -24,12 +25,12 @@ locals {
|
||||
}] : []
|
||||
metadata = merge(
|
||||
{
|
||||
"name"= "${local.app_slug}"
|
||||
"namespace"= var.namespace
|
||||
"labels"= var.labels
|
||||
"name" = local.app_slug
|
||||
"namespace" = var.namespace
|
||||
"labels" = var.labels
|
||||
},
|
||||
length(var.annotations) > 0 ? {
|
||||
"annotations"= var.annotations
|
||||
"annotations" = var.annotations
|
||||
} : {}
|
||||
)
|
||||
spec = {
|
||||
@@ -39,9 +40,9 @@ locals {
|
||||
selector = local.selector
|
||||
},
|
||||
"ExternalName" = {
|
||||
type = "ExternalName"
|
||||
externalName = var.target_host
|
||||
ports = local.ext_ports
|
||||
type = "ExternalName"
|
||||
externalName = var.target_host
|
||||
ports = local.ext_ports
|
||||
},
|
||||
"NodePort" = {
|
||||
type = "NodePort"
|
||||
@@ -53,6 +54,7 @@ locals {
|
||||
selector = local.selector
|
||||
ports = local.lb_ports
|
||||
externalTrafficPolicy = var.lb_policy
|
||||
ipFamilyPolicy = var.ip_family
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -64,3 +66,18 @@ resource "kubectl_manifest" "service" {
|
||||
spec: ${jsonencode(local.spec[var.svc_type])}
|
||||
EOF
|
||||
}
|
||||
resource "kubectl_manifest" "endpoint" {
|
||||
count = var.svc_type == "ExternalName" ? 1 : 0
|
||||
yaml_body = <<-EOF
|
||||
apiVersion: v1
|
||||
kind: Endpoints
|
||||
metadata:
|
||||
name: "${local.app_slug}"
|
||||
namespace: "${var.namespace}"
|
||||
labels: ${jsonencode(var.labels)}
|
||||
subsets:
|
||||
- addresses:
|
||||
- ip: ${var.target_host}
|
||||
ports: ${jsonencode([for port in var.ports : { "port" = port }])}
|
||||
EOF
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user