first commit
This commit is contained in:
8
service/providers.tf
Normal file
8
service/providers.tf
Normal file
@@ -0,0 +1,8 @@
|
||||
terraform {
|
||||
required_providers {
|
||||
kubectl = {
|
||||
source = "gavinbunney/kubectl"
|
||||
version = "~> 1.14.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
22
service/svc.tf
Normal file
22
service/svc.tf
Normal file
@@ -0,0 +1,22 @@
|
||||
locals {
|
||||
ports = [ for idx, target in var.targets : {
|
||||
"name" = target
|
||||
"port"= var.ports[idx]
|
||||
"protocol"= var.protocols[idx]
|
||||
"targetPort" = target
|
||||
}]
|
||||
}
|
||||
resource "kubectl_manifest" "service" {
|
||||
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)}
|
||||
EOF
|
||||
}
|
||||
24
service/variables.tf
Normal file
24
service/variables.tf
Normal file
@@ -0,0 +1,24 @@
|
||||
variable "component" {
|
||||
type = string
|
||||
}
|
||||
variable "instance" {
|
||||
type = string
|
||||
}
|
||||
variable "namespace" {
|
||||
type = string
|
||||
}
|
||||
variable "labels" {
|
||||
type = map(string)
|
||||
}
|
||||
variable "ports" {
|
||||
type = list
|
||||
default = [80]
|
||||
}
|
||||
variable "targets" {
|
||||
type = list
|
||||
default = ["http"]
|
||||
}
|
||||
variable "protocols" {
|
||||
type = list
|
||||
default = ["TCP"]
|
||||
}
|
||||
Reference in New Issue
Block a user