diff --git a/eks-addons.tf b/eks-addons.tf index 8e954fd..79c525a 100644 --- a/eks-addons.tf +++ b/eks-addons.tf @@ -1,23 +1,7 @@ module "eks_addons" { - source = "./modules/eks_addons" - enable_ingress_nginx = var.ingress_nginx_config.enable + source = "./modules/eks_addons" - ingress_nginx_helm_config = { - namespace = "nginx" - name = "ingress-nginx" - chart = "ingress-nginx" - repository = var.ingress_nginx_config.helm_repository - version = var.ingress_nginx_config.helm_version - description = "The NGINX HelmChart Ingress Controller deployment configuration" - create_namespace = true - dependency_update = true - values = [ - templatefile("${path.module}/templates/nginx_values.yaml", { - public_subnets = join(", ", local.public_subnets) - }), - yamlencode(var.ingress_nginx_config.chart_values) - ] - } + ingress_nginx_config = merge(var.ingress_nginx_config, { subnets_ids = local.public_subnets }) depends_on = [module.eks.eks_cluster_arn] } diff --git a/modules/eks_addons/ingress-nginx.tf b/modules/eks_addons/ingress-nginx.tf index f720563..3786a0a 100644 --- a/modules/eks_addons/ingress-nginx.tf +++ b/modules/eks_addons/ingress-nginx.tf @@ -1,22 +1,27 @@ resource "kubernetes_namespace_v1" "ingress_nginx" { - count = try(var.ingress_nginx_helm_config.create_namespace, true) && var.ingress_nginx_helm_config.namespace != "kube-system" && var.enable_ingress_nginx ? 1 : 0 + count = var.ingress_nginx_config.enable ? 1 : 0 metadata { - name = var.ingress_nginx_helm_config.namespace + name = "nginx" } } resource "helm_release" "ingress_nginx" { - count = var.enable_ingress_nginx ? 1 : 0 + count = var.ingress_nginx_config.enable ? 1 : 0 - namespace = var.ingress_nginx_helm_config.namespace - name = var.ingress_nginx_helm_config.name - chart = var.ingress_nginx_helm_config.chart - repository = var.ingress_nginx_helm_config.repository - version = var.ingress_nginx_helm_config.version - description = var.ingress_nginx_helm_config.description - create_namespace = var.ingress_nginx_helm_config.create_namespace - dependency_update = var.ingress_nginx_helm_config.dependency_update - values = var.ingress_nginx_helm_config.values - timeout = 1200 + namespace = "nginx" + name = "ingress-nginx" + chart = "ingress-nginx" + repository = var.ingress_nginx_config.helm_repository + version = var.ingress_nginx_config.helm_version + description = "The NGINX HelmChart Ingress Controller deployment configuration" + create_namespace = true + dependency_update = true + values = [ + templatefile("${path.module}/templates/nginx_values.yaml", { + public_subnets = join(", ", var.ingress_nginx_config.subnets_ids) + }), + yamlencode(var.ingress_nginx_config.chart_values) + ] + timeout = 1200 } diff --git a/templates/nginx_values.yaml b/modules/eks_addons/templates/nginx_values.yaml similarity index 100% rename from templates/nginx_values.yaml rename to modules/eks_addons/templates/nginx_values.yaml diff --git a/modules/eks_addons/variables.tf b/modules/eks_addons/variables.tf index 01c2ec7..08d5777 100644 --- a/modules/eks_addons/variables.tf +++ b/modules/eks_addons/variables.tf @@ -1,20 +1,10 @@ -variable "enable_ingress_nginx" { - description = "Enable Ingress Nginx helm release creation" - type = bool - default = false -} - -variable "ingress_nginx_helm_config" { - description = "Helm Configuration for Ingress Nginx" +variable "ingress_nginx_config" { + description = "Ingress Nginx configuration" type = object({ - namespace = string - name = string - chart = string - repository = string - version = string - description = string - create_namespace = bool - dependency_update = bool - values = list(string) + enable = bool + helm_repository = string + helm_version = string + chart_values = map(any) + subnets_ids = list(string) }) }