From 39acc3e8c9f61122c1859b31250d8f357da22643 Mon Sep 17 00:00:00 2001 From: "nicola.bucci" Date: Wed, 6 Nov 2024 17:06:29 +0100 Subject: [PATCH] add additional managed namespaces --- main.tf | 5 ++++- variables.tf | 6 ++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/main.tf b/main.tf index 45637e9..6b7576e 100644 --- a/main.tf +++ b/main.tf @@ -6,6 +6,8 @@ locals { ) final_namespace = var.create_namespace ? resource.kubernetes_namespace_v1.this[0].metadata[0].name : data.kubernetes_namespace_v1.this[0].metadata[0].name + + managed_namespaces = distinct(concat(var.managed_namespaces, var.additional_managed_namespaces)) } resource "kubernetes_namespace_v1" "this" { @@ -38,6 +40,7 @@ resource "kubernetes_service_account_v1" "this" { resource "kubernetes_secret_v1" "this" { metadata { + # This is the prefix, used by the server, to generate a unique name ONLY IF the name field has not been provided. This value will also be combined with a unique suffix. generate_name = "${var.service_account_name}-" namespace = local.final_namespace labels = local.k8s_full_labels @@ -103,7 +106,7 @@ resource "kubernetes_cluster_role_v1" "namespace_scoped" { } resource "kubernetes_role_binding_v1" "this" { - for_each = toset(var.managed_namespaces) + for_each = toset(local.managed_namespaces) metadata { name = var.role_binding_name diff --git a/variables.tf b/variables.tf index 63e7f28..3166e75 100644 --- a/variables.tf +++ b/variables.tf @@ -49,6 +49,12 @@ variable "managed_namespaces" { default = [] } +variable "additional_managed_namespaces" { + description = "List of additional namespaces where the controller should manage the scale of deployments." + type = list(string) + default = [] +} + variable "managed_namespaces_label_selector" { description = "Label selector for the namespaces where the controller should manage the scale of deployments. The namespaces fetched by this selector will be merged with the `managed_namespaces` variable." type = map(string)