first commit

This commit is contained in:
2024-01-10 13:23:08 +01:00
commit e0baae6132
25 changed files with 765 additions and 0 deletions

8
service/providers.tf Normal file
View File

@@ -0,0 +1,8 @@
terraform {
required_providers {
kubectl = {
source = "gavinbunney/kubectl"
version = "~> 1.14.0"
}
}
}

22
service/svc.tf Normal file
View 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
View 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"]
}