diff --git a/module.tf b/module.tf index 079712d..a1ce991 100644 --- a/module.tf +++ b/module.tf @@ -15,7 +15,7 @@ variable "kubernetes" { name = string pvc_size = string mount_path = string -# database = optional(bool,false) + # database = optional(bool,false) }))) environment = optional(map(object({ name = optional(string) @@ -58,9 +58,9 @@ locals { name = pvc.name pvc_size = pvc.pvc_size mount_path = pvc.mount_path -# database = value.database -# database = pvc.database - namespace = coalesce(value.namespace, key) + # database = value.database + # database = pvc.database + namespace = coalesce(value.namespace, key) }] if value.enabled == true && value.pvc != null ]) } @@ -190,151 +190,13 @@ resource "kubernetes_service" "automatic_service_database" { } + + + + + + resource "kubernetes_deployment_v1" "automatic" { - for_each = { for key, value in var.kubernetes : key => value if value.enabled == true } - metadata { - namespace = coalesce(each.value.namespace, each.key) - name = each.key - labels = { - app = each.key - deployment_method = "Terraform" - } - } - - spec { - replicas = each.value.replicas - - selector { - match_labels = { - app = each.key - } - } - - template { - metadata { - labels = { - app = each.key - deployment_method = "Terraform" - } - } - - spec { - container { - image = each.value.image - name = coalesce(each.value.name, each.key) - dynamic "port" { - for_each = each.value.service_port != null ? [""] : [] - content { - container_port = each.value.service_port - name = each.key - } - } - - - dynamic "volume_mount" { - for_each = each.value.pvc != null ? each.value.pvc : {} -# for_each = each.value.pvc != null ? (each.value.pvc.database != null ? each.value.pvc : {}) : {} - content { - mount_path = volume_mount.value.mount_path - name = "${volume_mount.value.name}-pvc" - } - } - - - - - dynamic "env" { - for_each = each.value.environment != null ? each.value.environment : {} - content { - name = env.key - value = env.value.value != null ? env.value.value : null - 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 - optional = true - } - } - # dynamic "secret_ref" { - # for_each = [1] - # content { - # name = env.value.value_from.secret_key_ref.name - # optional = true - # } - # } - } - } - - } - } - - - resources { - limits = { - cpu = each.value.requirements.limits-cpu - memory = each.value.requirements.limits-memory - } - requests = { - cpu = each.value.requirements.requests-cpu - memory = each.value.requirements.requests-memory - } - } - - dynamic "liveness_probe" { - for_each = each.value.liveness_tcp_socket != null || each.value.liveness_http_get != null ? [""] : [] - content { - dynamic "tcp_socket" { - for_each = each.value.liveness_tcp_socket != null ? [""] : [] - content { - port = each.value.liveness_tcp_socket - } - } - - - dynamic "http_get" { - for_each = each.value.liveness_http_get != null ? [""] : [] - content { - port = each.value.liveness_http_get - path = coalesce(each.value.liveness_http_get_path, "/") - } - } - - initial_delay_seconds = 3 - period_seconds = 3 - } - } - } - - - dynamic "volume" { - for_each = each.value.pvc != null ? each.value.pvc : {} - content { - name = "${volume.value.name}-pvc" - persistent_volume_claim { - claim_name = "${volume.value.name}-pvc" - } - } - } - - } - } - } -} - } - - - } - - -} - - - -resource "kubernetes_deployment_v1" "database_automatic" { for_each = { for key, value in var.kubernetes : key => value if value.enabled == true } metadata { namespace = coalesce(each.value.namespace, each.key) @@ -397,8 +259,138 @@ resource "kubernetes_deployment_v1" "database_automatic" { 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 + name = env.value.value_from.secret_key_ref.name + key = env.value.value_from.secret_key_ref.key + optional = true + } + } + } + } + + } + } + + + resources { + limits = { + cpu = each.value.requirements.limits-cpu + memory = each.value.requirements.limits-memory + } + requests = { + cpu = each.value.requirements.requests-cpu + memory = each.value.requirements.requests-memory + } + } + + dynamic "liveness_probe" { + for_each = each.value.liveness_tcp_socket != null || each.value.liveness_http_get != null ? [""] : [] + content { + dynamic "tcp_socket" { + for_each = each.value.liveness_tcp_socket != null ? [""] : [] + content { + port = each.value.liveness_tcp_socket + } + } + + + dynamic "http_get" { + for_each = each.value.liveness_http_get != null ? [""] : [] + content { + port = each.value.liveness_http_get + path = coalesce(each.value.liveness_http_get_path, "/") + } + } + + initial_delay_seconds = 3 + period_seconds = 3 + } + } + } + + + dynamic "volume" { + for_each = each.value.pvc != null ? each.value.pvc : {} + content { + name = "${volume.value.name}-pvc" + persistent_volume_claim { + claim_name = "${volume.value.name}-pvc" + } + } + } + + } + } + } +} + + + + +resource "kubernetes_deployment_v1" "database-automatic" { + for_each = { for key, value in var.kubernetes : key => value if value.enabled == true } + metadata { + namespace = coalesce(each.value.namespace, each.key) + name = coalesce(each.value.namespace, each.key) + labels = { + app = each.key + deployment_method = "Terraform" + } + } + + spec { + replicas = each.value.replicas + + selector { + match_labels = { + app = each.key + } + } + + template { + metadata { + labels = { + app = each.key + deployment_method = "Terraform" + } + } + + spec { + container { + image = each.value.image + name = coalesce(each.value.name, each.key) + dynamic "port" { + for_each = each.value.service_port != null ? [""] : [] + content { + container_port = each.value.service_port + name = each.key + } + } + + + dynamic "volume_mount" { + for_each = each.value.pvc != null ? each.value.pvc : {} + content { + mount_path = volume_mount.value.mount_path + name = "${volume_mount.value.name}-pvc" + } + } + + + + + dynamic "env" { + for_each = each.value.environment != null ? each.value.environment : {} + content { + name = env.key + value = env.value.value != null ? env.value.value : null + 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 optional = true } }