automatic pvc is working
This commit is contained in:
@@ -14,10 +14,15 @@ variable "kubernetes" {
|
||||
type = map(object({
|
||||
#service = string
|
||||
# pvc_name = optional(string)
|
||||
name = optional(string)
|
||||
image = string
|
||||
mount_path = optional(string, "/mount")
|
||||
pvc_size = optional(string)
|
||||
name = optional(string)
|
||||
image = string
|
||||
# mount_path = optional(string, "/mount")
|
||||
# pvc_size = optional(string)
|
||||
pvc = optional(map(object({
|
||||
name = string
|
||||
pvc_size = string
|
||||
mount_path = string
|
||||
})))
|
||||
replicas = optional(number, 1)
|
||||
namespace = optional(string)
|
||||
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" {
|
||||
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" {
|
||||
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 {
|
||||
namespace = coalesce(each.value.namespace, each.key)
|
||||
name = "${each.key}-pvc"
|
||||
# namespace = coalesce(each.value.namespace, each.key)
|
||||
namespace = each.value.namespace
|
||||
name = "${each.value.name}-pvc"
|
||||
}
|
||||
spec {
|
||||
access_modes = ["ReadWriteMany"]
|
||||
@@ -135,15 +157,15 @@ resource "kubernetes_deployment_v1" "automatic" {
|
||||
}
|
||||
}
|
||||
|
||||
dynamic "volume_mount" {
|
||||
for_each = each.value.pvc_size != null ? [""] : []
|
||||
content {
|
||||
# dynamic "volume_mount" {
|
||||
# for_each = each.value.pvc_size != null ? [""] : []
|
||||
# content {
|
||||
|
||||
mount_path = each.value.mount_path
|
||||
name = "${each.key}-volume"
|
||||
# mount_path = each.value.mount_path
|
||||
# name = "${each.key}-volume"
|
||||
|
||||
}
|
||||
}
|
||||
# }
|
||||
# }
|
||||
|
||||
|
||||
#########################################
|
||||
@@ -211,7 +233,8 @@ resource "kubernetes_deployment_v1" "automatic" {
|
||||
}
|
||||
|
||||
dynamic "volume" {
|
||||
for_each = each.value.pvc_size != null ? [""] : []
|
||||
for_each = each.value.pvc != null ? [""] : []
|
||||
# for_each = each.value.pvc_size != null ? [""] : []
|
||||
content {
|
||||
name = "${each.key}-volume"
|
||||
persistent_volume_claim {
|
||||
|
||||
+34
-12
@@ -13,21 +13,36 @@ kubernetes = {
|
||||
requests-cpu = "300m"
|
||||
requests-memory = "400Mi"
|
||||
}
|
||||
pvc = {
|
||||
first = {
|
||||
name = "onitama"
|
||||
pvc_size = "1Mi"
|
||||
mount_path = "/code"
|
||||
} }
|
||||
}
|
||||
|
||||
djangoterra = {
|
||||
enabled = false
|
||||
# image = "localhost:31795/django-python"
|
||||
image = "gitea.tryton.geeraert.eu/pi-ux-ce/django-python:1.0.0"
|
||||
# image = "nginx:latest"
|
||||
pvc_size = "10Mi"
|
||||
mount_path = "/code"
|
||||
service_port = 8000
|
||||
onitama = {
|
||||
enabled = true
|
||||
image = "ghcr.io/jackadamson/onitama:latest"
|
||||
service_port = 8080
|
||||
requirements = {
|
||||
limits-cpu = "200m"
|
||||
limits-memory = "200Mi"
|
||||
requests-cpu = "50m"
|
||||
requests-memory = "50Mi"
|
||||
limits-cpu = "50m"
|
||||
limits-memory = "50Mi"
|
||||
requests-cpu = "25m"
|
||||
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-second_PORT" , value = "81"
|
||||
# }
|
||||
pvc = {
|
||||
first = {
|
||||
name = "nginx"
|
||||
pvc_size = "1Mi"
|
||||
mount_path = "/code"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
redis = {
|
||||
|
||||
Reference in New Issue
Block a user