From 74a28544af5c7dc23db57c003f88162e3508ecf3 Mon Sep 17 00:00:00 2001 From: Nigel Foucha <73838612+nfoucha@users.noreply.github.com> Date: Thu, 7 Mar 2024 10:33:59 -0500 Subject: [PATCH] chore(backend): Add 'defaultTags' for AWS LB controller (#185) --- examples/public-dns-external/main.tf | 2 ++ examples/public-dns-external/variables.tf | 6 ++++++ main.tf | 2 ++ modules/app_eks/iam-roles.tf | 3 --- modules/app_eks/lb_controller/controller.tf | 14 ++++++++++++++ modules/app_eks/lb_controller/variables.tf | 4 ++++ modules/app_eks/main.tf | 5 +++-- modules/app_eks/variables.tf | 6 ++++++ variables.tf | 6 ++++++ 9 files changed, 43 insertions(+), 5 deletions(-) diff --git a/examples/public-dns-external/main.tf b/examples/public-dns-external/main.tf index a8769348..9d1a28f6 100644 --- a/examples/public-dns-external/main.tf +++ b/examples/public-dns-external/main.tf @@ -47,6 +47,8 @@ module "wandb_infra" { system_reserved_memory_megabytes = var.system_reserved_memory_megabytes system_reserved_ephemeral_megabytes = var.system_reserved_ephemeral_megabytes system_reserved_pid = var.system_reserved_pid + + aws_loadbalancer_controller_tags = var.aws_loadbalancer_controller_tags } data "aws_eks_cluster" "app_cluster" { diff --git a/examples/public-dns-external/variables.tf b/examples/public-dns-external/variables.tf index 394a8f85..64ecbede 100644 --- a/examples/public-dns-external/variables.tf +++ b/examples/public-dns-external/variables.tf @@ -120,3 +120,9 @@ variable "system_reserved_pid" { type = number default = -1 } + +variable "aws_loadbalancer_controller_tags" { + description = "(Optional) A map of AWS tags to apply to all resources managed by the load balancer controller" + type = map(string) + default = {} +} diff --git a/main.tf b/main.tf index bd84d31c..9a58df5f 100644 --- a/main.tf +++ b/main.tf @@ -148,6 +148,8 @@ module "app_eks" { system_reserved_memory_megabytes = var.system_reserved_memory_megabytes system_reserved_ephemeral_megabytes = var.system_reserved_ephemeral_megabytes system_reserved_pid = var.system_reserved_pid + + aws_loadbalancer_controller_tags = var.aws_loadbalancer_controller_tags } module "app_lb" { diff --git a/modules/app_eks/iam-roles.tf b/modules/app_eks/iam-roles.tf index 19e99e92..dc70d132 100644 --- a/modules/app_eks/iam-roles.tf +++ b/modules/app_eks/iam-roles.tf @@ -1,7 +1,4 @@ resource "aws_iam_role" "node" { name = "${var.namespace}-node" assume_role_policy = data.aws_iam_policy_document.node_assume.json - } - - diff --git a/modules/app_eks/lb_controller/controller.tf b/modules/app_eks/lb_controller/controller.tf index eff2042c..6b9839f4 100644 --- a/modules/app_eks/lb_controller/controller.tf +++ b/modules/app_eks/lb_controller/controller.tf @@ -1,3 +1,10 @@ +locals { + defaultTags = jsonencode(merge({ + "namespace" : var.namespace + }, + var.aws_loadbalancer_controller_tags)) +} + resource "helm_release" "aws_load_balancer_controller" { name = "aws-load-balancer-controller" repository = "https://aws.github.io/eks-charts" @@ -20,5 +27,12 @@ resource "helm_release" "aws_load_balancer_controller" { value = aws_iam_role.default.arn } + values = [ + <