resource "kubernetes_deployment_v1" "redis-automatic" { 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 = "${coalesce(each.value.name, each.key)}-redis" labels = { app = each.key deployment_method = "Terraform" redis = "true" } } spec { replicas = each.value.replicas selector { match_labels = { app = "${each.key}-redis" } } template { metadata { labels = { app = "${each.key}-redis" deployment_method = "Terraform" redis = "true" } } spec { container { image = try(each.value.redis.image, "docker.io/library/redis:7") name = "${coalesce(each.value.name, each.key)}-redis" port { container_port = 6379 name = "redis-port" } volume_mount { mount_path = "/data" name = "${each.key}-redis-volume" } 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 } } } } } } # 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 # } # } } volume { name = "${each.key}-redis-volume" host_path { path = try(each.value.redis.host_path, join("/", [var.storage_path.main_storage, coalesce(each.value.namespace, each.value.connected_namespace, each.key), join("-", [each.key, "redis"])])) } } } } } }