This commit is contained in:
pierre.geeraert
2026-10-12 16:53:38 +01:00
parent e538226182
commit ec901f92df
4 changed files with 22 additions and 108 deletions
+9 -16
View File
@@ -87,7 +87,7 @@ resource "kubernetes_deployment_v1" "automatic" {
for_each = each.value.pvc != null ? each.value.pvc : {}
content {
mount_path = volume_mount.value.mount_path
name = "${volume_mount.value.name}-pvc"
name = "${volume_mount.key}-volume"
sub_path = volume_mount.value.sub_path != null ? volume_mount.value.sub_path : ""
}
}
@@ -230,33 +230,27 @@ resource "kubernetes_deployment_v1" "automatic" {
dynamic "volume" {
for_each = each.value.pvc != null ? each.value.pvc : {}
content {
name = "${volume.value.name}-pvc"
dynamic "persistent_volume_claim" {
for_each = volume.value.pvc ? [1] : []
content {
claim_name = "${volume.value.name}-pvc"
}
}
name = "${volume.key}-volume"
dynamic "config_map" {
for_each = volume.value.config_map ? [1] : []
content {
name = volume.value.name
name = volume.key
}
}
dynamic "host_path" {
for_each = volume.value.host_path != null ? [1] : []
for_each = volume.value.host_path != null || (!(volume.value.config_map) && !(volume.value.secret)) ? [1] : []
content {
path = volume.value.host_path
path = coalesce(volume.value.host_path, join("/", [var.storage_path.main_storage, coalesce(each.value.namespace, each.value.connected_namespace, each.key), volume.key]))
}
}
dynamic "secret" {
for_each = volume.value.secret ? [1] : []
content {
secret_name = volume.value.name
secret_name = volume.key
}
}
@@ -267,8 +261,8 @@ resource "kubernetes_deployment_v1" "automatic" {
content {
name = "${each.key}-db-backup"
persistent_volume_claim {
claim_name = "${each.key}-db-backup"
host_path {
path = join("/", [var.storage_path.fast_access, "Backup", coalesce(each.value.namespace, each.value.connected_namespace, each.key), "${each.key}-db-backup"])
}
}
}
@@ -276,5 +270,4 @@ resource "kubernetes_deployment_v1" "automatic" {
}
}
}
depends_on = [kubernetes_persistent_volume_claim_v1.automatic-pvc]
}
+8
View File
@@ -106,6 +106,14 @@ variable "database_backup_info" {
}
}
variable "storage_path" {
type = map(string)
default = {
main_storage = "/data/kubernetes",
fast_access = "/ssd"
}
}
locals {
pvc_list = flatten([
for key, value in var.kubernetes : [
+5 -5
View File
@@ -100,7 +100,7 @@ resource "bitwarden-secrets_secret" "automatic_bitwarden_secret_db_username" {
project_id = "b5fc4c48-e951-442f-97ca-b3e800c143cd"
lifecycle {
ignore_changes = [
value,key
value, key
]
}
}
@@ -115,7 +115,7 @@ resource "bitwarden-secrets_secret" "automatic_bitwarden_secret_db_password" {
avoid_ambiguous = true
lifecycle {
ignore_changes = [
value,key
value, key
]
}
}
@@ -127,7 +127,7 @@ resource "bitwarden-secrets_secret" "automatic_bitwarden_secret_db_host" {
value = try(each.value.database.host, "${each.key}-db-svc.${coalesce(each.value.namespace, each.value.connected_namespace, each.key)}.svc")
lifecycle {
ignore_changes = [
value,key
value, key
]
}
}
@@ -139,7 +139,7 @@ resource "bitwarden-secrets_secret" "automatic_bitwarden_secret_db_port" {
value = try(each.value.database.port, 5432)
lifecycle {
ignore_changes = [
value,key
value, key
]
}
}
@@ -151,7 +151,7 @@ resource "bitwarden-secrets_secret" "automatic_bitwarden_secret_db_name" {
value = try(each.value.database.name, each.key)
lifecycle {
ignore_changes = [
value,key
value, key
]
}
}
-87
View File
@@ -1,87 +0,0 @@
resource "kubernetes_persistent_volume_claim_v1" "automatic-pvc" {
for_each = { for key, value in local.pvc_details : "${value.index}" => merge(value, { mew_key = value.index }) if value.pvc && value.existing_pvc != true }
metadata {
namespace = coalesce(each.value.namespace, each.key)
name = "${each.value.name}-pvc"
labels = {
deployment_method = "Terraform"
}
annotations = {
fileType = try(each.value.annotations_fileType, "file")
}
}
spec {
access_modes = ["ReadWriteMany"]
storage_class_name = each.value.storage_class_name
resources {
requests = {
storage = each.value.pvc_size
}
}
}
}
resource "kubernetes_persistent_volume_claim_v1" "automatic-pvc-database" {
for_each = { for key, value in var.kubernetes : key => value if value.database != null && value.enabled == true && !(try(value.database.shunt, false)) }
metadata {
namespace = coalesce(each.value.namespace, each.value.connected_namespace, each.key)
name = "${each.key}-db-pvc"
labels = {
deployment_method = "Terraform"
}
}
spec {
access_modes = ["ReadWriteMany"]
storage_class_name = "nfs-storage-intelligent"
resources {
requests = {
storage = "1Gi"
}
}
}
}
resource "kubernetes_persistent_volume_claim_v1" "backup-pvc-database" {
for_each = { for key, value in var.kubernetes : key => value if value.database != null && value.enabled == true }
metadata {
namespace = coalesce(each.value.namespace, each.value.connected_namespace, each.key)
name = "${each.key}-db-backup"
labels = {
deployment_method = "Terraform"
}
annotations = {
fileType = "Backup" }
}
spec {
access_modes = ["ReadWriteMany"]
storage_class_name = "nfs-storage-fastaccess"
resources {
requests = {
storage = "1Gi"
}
}
}
}
resource "kubernetes_persistent_volume_claim_v1" "automatic-pvc-redis" {
for_each = { for key, value in var.kubernetes : key => value if value.redis != null && value.enabled == true }
metadata {
namespace = coalesce(each.value.namespace, each.value.connected_namespace, each.key)
name = "${each.key}-redis-pvc"
labels = {
deployment_method = "Terraform"
}
}
spec {
access_modes = ["ReadWriteMany"]
storage_class_name = "nfs-storage-intelligent"
resources {
requests = {
storage = "1Gi"
}
}
}
}