automatic pvc is working

This commit is contained in:
2024-11-18 13:26:49 +00:00
parent e6de45c700
commit baf444f201
2 changed files with 72 additions and 27 deletions
+38 -15
View File
@@ -14,10 +14,15 @@ variable "kubernetes" {
type = map(object({ type = map(object({
#service = string #service = string
# pvc_name = optional(string) # pvc_name = optional(string)
name = optional(string) name = optional(string)
image = string image = string
mount_path = optional(string, "/mount") # mount_path = optional(string, "/mount")
pvc_size = optional(string) # pvc_size = optional(string)
pvc = optional(map(object({
name = string
pvc_size = string
mount_path = string
})))
replicas = optional(number, 1) replicas = optional(number, 1)
namespace = optional(string) namespace = optional(string)
service_port = optional(number) service_port = optional(number)
@@ -41,7 +46,21 @@ variable "kubernetes" {
} }
locals {
pvc_details = flatten([
for key, value in var.kubernetes : [
for pvc in value.pvc : {
name = pvc.name
pvc_size = pvc.pvc_size
mount_path = pvc.mount_path
namespace = coalesce(value.namespace, key)
}] if value.enabled == true && value.pvc != null
])
}
output "pvc_test" {
value = { for key, value in local.pvc_details : key => value }
}
resource "kubernetes_namespace" "automatic" { resource "kubernetes_namespace" "automatic" {
for_each = { for key, value in var.kubernetes : key => value if value.enabled == true } for_each = { for key, value in var.kubernetes : key => value if value.enabled == true }
@@ -55,10 +74,13 @@ resource "kubernetes_namespace" "automatic" {
resource "kubernetes_persistent_volume_claim" "automatic-pvc" { resource "kubernetes_persistent_volume_claim" "automatic-pvc" {
for_each = { for key, value in var.kubernetes : key => value if value.pvc_size != null && value.enabled == true } ## for_each = { for key, value in var.kubernetes : key => value if value.pvc_size != null && value.enabled == true }
for_each = { for key, value in local.pvc_details : key => value }
metadata { metadata {
namespace = coalesce(each.value.namespace, each.key) # namespace = coalesce(each.value.namespace, each.key)
name = "${each.key}-pvc" namespace = each.value.namespace
name = "${each.value.name}-pvc"
} }
spec { spec {
access_modes = ["ReadWriteMany"] access_modes = ["ReadWriteMany"]
@@ -135,15 +157,15 @@ resource "kubernetes_deployment_v1" "automatic" {
} }
} }
dynamic "volume_mount" { # dynamic "volume_mount" {
for_each = each.value.pvc_size != null ? [""] : [] # for_each = each.value.pvc_size != null ? [""] : []
content { # content {
mount_path = each.value.mount_path # mount_path = each.value.mount_path
name = "${each.key}-volume" # name = "${each.key}-volume"
} # }
} # }
######################################### #########################################
@@ -211,7 +233,8 @@ resource "kubernetes_deployment_v1" "automatic" {
} }
dynamic "volume" { dynamic "volume" {
for_each = each.value.pvc_size != null ? [""] : [] for_each = each.value.pvc != null ? [""] : []
# for_each = each.value.pvc_size != null ? [""] : []
content { content {
name = "${each.key}-volume" name = "${each.key}-volume"
persistent_volume_claim { persistent_volume_claim {
+34 -12
View File
@@ -13,21 +13,36 @@ kubernetes = {
requests-cpu = "300m" requests-cpu = "300m"
requests-memory = "400Mi" requests-memory = "400Mi"
} }
pvc = {
first = {
name = "onitama"
pvc_size = "1Mi"
mount_path = "/code"
} }
} }
djangoterra = { onitama = {
enabled = false enabled = true
# image = "localhost:31795/django-python" image = "ghcr.io/jackadamson/onitama:latest"
image = "gitea.tryton.geeraert.eu/pi-ux-ce/django-python:1.0.0" service_port = 8080
# image = "nginx:latest"
pvc_size = "10Mi"
mount_path = "/code"
service_port = 8000
requirements = { requirements = {
limits-cpu = "200m" limits-cpu = "50m"
limits-memory = "200Mi" limits-memory = "50Mi"
requests-cpu = "50m" requests-cpu = "25m"
requests-memory = "50Mi" requests-memory = "25Mi"
}
environment_variables = { PORT = 80 }
pvc = {
first = {
name = "onitama"
pvc_size = "1Mi"
mount_path = "/code"
}
second = {
name = "onitamadeux"
pvc_size = "2Mi"
mount_path = "/deuxcode"
}
} }
} }
@@ -57,6 +72,13 @@ kubernetes = {
# name = "NGINX_PORT" , value = "80" # name = "NGINX_PORT" , value = "80"
# name = "NGINX-second_PORT" , value = "81" # name = "NGINX-second_PORT" , value = "81"
# } # }
pvc = {
first = {
name = "nginx"
pvc_size = "1Mi"
mount_path = "/code"
}
}
} }
redis = { redis = {