Improve modules
This commit is contained in:
@@ -1,22 +1,40 @@
|
||||
locals {
|
||||
ports = [ for idx, target in var.targets : {
|
||||
"name" = target
|
||||
"port"= var.ports[idx]
|
||||
"protocol"= var.protocols[idx]
|
||||
cluster_ports = var.svc_type == "ClusterIP" ? [for idx, target in var.targets : {
|
||||
"name" = target
|
||||
"port" = var.ports[idx]
|
||||
"protocol" = var.protocols[idx]
|
||||
"targetPort" = target
|
||||
}]
|
||||
}] : []
|
||||
node_ports = var.svc_type == "NodePort" ? [for idx, port in var.ports : {
|
||||
"port" = port
|
||||
"targetPort" = port
|
||||
"nodePort" = var.node_ports[idx]
|
||||
}] : []
|
||||
spec = {
|
||||
"ClusterIP" = {
|
||||
type = "ClusterIP"
|
||||
ports = local.cluster_ports
|
||||
selector = var.labels
|
||||
},
|
||||
"ExternalName" = {
|
||||
type = "ExternalName"
|
||||
externalName = var.target_host
|
||||
},
|
||||
"NodePort" = {
|
||||
type = "NodePort"
|
||||
selector = var.labels
|
||||
ports = local.node_ports
|
||||
}
|
||||
}
|
||||
}
|
||||
resource "kubectl_manifest" "service" {
|
||||
yaml_body = <<-EOF
|
||||
yaml_body = <<-EOF
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: "${var.instance}-${var.component}"
|
||||
namespace: "${var.namespace}"
|
||||
labels: ${jsonencode(var.labels)}
|
||||
spec:
|
||||
type: ClusterIP
|
||||
ports: ${jsonencode(local.ports)}
|
||||
selector: ${jsonencode(var.labels)}
|
||||
spec: ${jsonencode(local.spec[var.svc_type])}
|
||||
EOF
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user