2024-11-18 17:08:23 +00:00
parent d2943fff6d
commit 8890d057cb
2 changed files with 67 additions and 14 deletions
+47 -5
View File
@@ -19,6 +19,17 @@ variable "kubernetes" {
pvc_size = string
mount_path = string
})))
environment = optional(map(object({
name = string
value = optional(string)
value_from = optional(object({
secret_key_ref = object({
name = string
key = string
})
}))
# secret_name = optional(string)
})))
replicas = optional(number, 1)
namespace = optional(string)
service_port = optional(number)
@@ -51,8 +62,23 @@ locals {
])
}
output "pvc_test" {
value = { for key, value in local.pvc_details : key => value }
locals {
env_details = flatten([
for key, value in var.kubernetes : [
for index, env in value.environment_variables : {
index = index
name = env
}] if value.enabled == true && value.environment_variables != null
])
}
#output "pvc_test" {
# value = { for key, value in local.pvc_details : key => value }
#}
output "env_test" {
value = { for key, value in local.env_details : key => value }
}
resource "kubernetes_namespace" "automatic" {
@@ -70,7 +96,7 @@ resource "kubernetes_namespace" "automatic" {
resource "kubernetes_persistent_volume_claim" "automatic-pvc" {
for_each = { for key, value in local.pvc_details : "${value.index}" => merge(value, {mew_key = value.index}) }
for_each = { for key, value in local.pvc_details : "${value.index}" => merge(value, { mew_key = value.index }) }
metadata {
namespace = each.value.namespace
name = "${each.value.name}-pvc"
@@ -169,10 +195,26 @@ resource "kubernetes_deployment_v1" "automatic" {
dynamic "env" {
for_each = each.value.environment_variables != null ? each.value.environment_variables : {}
for_each = each.value.environment != null ? each.value.environment : {}
content {
name = env.key
value = env.value
dynamic "value_from" {
for_each = env.value.value_from != null ? env.value.value_from : {}
content {
dynamic "secret_key_ref" {
for_each = [1]
content {
name = env.value.value_from.secret_key_ref.name
key = env.value.value_from.secret_key_ref.key
}
}
}
}
# value = env.value
# value_from = {
# secret_key_ref = {
# name = test } }
}
}
+19 -8
View File
@@ -31,23 +31,34 @@ kubernetes = {
requests-cpu = "25m"
requests-memory = "25Mi"
}
environment_variables = { PORT = 80 }
pvc = {
first = {
name = "onitama"
pvc_size = "1Mi"
mount_path = "/code"
# environment_variables = { PORT = 80, test = 22 }
environment = {
MY_VAR = {
name = "MY_VAR"
value_from = {
secret_key_ref = {
name = "my_secret"
key = "latest"
}
second = {
}
}
}
pvc = {
onitamadeux = {
name = "onitamadeux"
pvc_size = "2Mi"
mount_path = "/deuxcode"
}
onitama = {
name = "onitama"
pvc_size = "1Mi"
mount_path = "/code"
}
}
}
nginx = {
enabled = true
enabled = false
namespace = "testnginx"
#image = "localhost:31795/django-python"
image = "nginx:latest"