another try for the hostpath
This commit is contained in:
+1
-9
@@ -191,13 +191,6 @@ resource "kubernetes_deployment_v1" "automatic" {
|
||||
content {
|
||||
name = "${volume.value.name}-pvc"
|
||||
|
||||
dynamic "persistent_volume_claim" {
|
||||
for_each = volume.value.pvc ? [1] : []
|
||||
content {
|
||||
claim_name = "${volume.value.name}-pvc"
|
||||
}
|
||||
}
|
||||
|
||||
dynamic "config_map" {
|
||||
for_each = volume.value.config_map ? [1] : []
|
||||
content {
|
||||
@@ -208,7 +201,7 @@ resource "kubernetes_deployment_v1" "automatic" {
|
||||
dynamic "host_path" {
|
||||
for_each = volume.value.host_path != null ? [1] : []
|
||||
content {
|
||||
path = volume.value.host_path
|
||||
path = coalesce(volume.value.host_folderpath, null)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -235,7 +228,6 @@ resource "kubernetes_deployment_v1" "automatic" {
|
||||
}
|
||||
}
|
||||
}
|
||||
depends_on = [kubernetes_persistent_volume_claim_v1.automatic-pvc]
|
||||
}
|
||||
|
||||
|
||||
|
||||
+4
-35
@@ -23,14 +23,14 @@ variable "kubernetes" {
|
||||
image = string
|
||||
pvc = optional(map(object({
|
||||
name = string
|
||||
pvc = optional(bool, false)
|
||||
|
||||
config_map = optional(bool, false)
|
||||
secret = optional(bool, false)
|
||||
host_path = optional(string)
|
||||
pvc_size = optional(string)
|
||||
host_path = optional(bool, false)
|
||||
host_folderpath = optional(string)
|
||||
|
||||
storage_class_name = optional(string, "nfs-storage-intelligent")
|
||||
annotations_fileType = optional(string)
|
||||
existing_pvc = optional(bool, false)
|
||||
mount_path = string
|
||||
sub_path = optional(string)
|
||||
})))
|
||||
@@ -81,38 +81,7 @@ variable "shunt_docker" {
|
||||
}
|
||||
|
||||
|
||||
locals {
|
||||
pvc_list = flatten([
|
||||
for key, value in var.kubernetes : [
|
||||
for index, pvc in value.pvc : {
|
||||
key = "${coalesce(value.namespace, value.connected_namespace, key)}/${pvc.name}"
|
||||
index = index
|
||||
pvc = pvc.pvc
|
||||
name = pvc.name
|
||||
pvc_size = pvc.pvc_size
|
||||
mount_path = pvc.mount_path
|
||||
storage_class_name = pvc.storage_class_name
|
||||
annotations_fileType = pvc.annotations_fileType
|
||||
existing_pvc = pvc.existing_pvc
|
||||
sub_path = pvc.sub_path
|
||||
namespace = coalesce(value.namespace, value.connected_namespace, key)
|
||||
}] if value.enabled == true && value.pvc != null && value.docker != true
|
||||
])
|
||||
|
||||
# group duplicates instead of throwing an error
|
||||
pvc_map_grouped = {
|
||||
for p in local.pvc_list :
|
||||
p.key => p...
|
||||
}
|
||||
|
||||
# keep only one PVC per key (take the first)
|
||||
pvc_map = {
|
||||
for k, list in local.pvc_map_grouped :
|
||||
k => list[0]
|
||||
}
|
||||
|
||||
pvc_details = values(local.pvc_map)
|
||||
}
|
||||
|
||||
locals {
|
||||
env_details = flatten([
|
||||
|
||||
@@ -1,86 +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 && value.docker != 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)) && value.docker != true }
|
||||
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 && value.docker != 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 && value.docker != 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"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user