Skip to content

Commit

Permalink
chore(backend): Add 'defaultTags' for AWS LB controller (#185)
Browse files Browse the repository at this point in the history
  • Loading branch information
nfoucha authored Mar 7, 2024
1 parent 258fb12 commit 74a2854
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 5 deletions.
2 changes: 2 additions & 0 deletions examples/public-dns-external/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down
6 changes: 6 additions & 0 deletions examples/public-dns-external/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
}
2 changes: 2 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down
3 changes: 0 additions & 3 deletions modules/app_eks/iam-roles.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
resource "aws_iam_role" "node" {
name = "${var.namespace}-node"
assume_role_policy = data.aws_iam_policy_document.node_assume.json

}


14 changes: 14 additions & 0 deletions modules/app_eks/lb_controller/controller.tf
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -20,5 +27,12 @@ resource "helm_release" "aws_load_balancer_controller" {
value = aws_iam_role.default.arn
}

values = [
<<EOT
defaultTags:
${local.defaultTags}
EOT
]

depends_on = [aws_iam_role_policy_attachment.default]
}
4 changes: 4 additions & 0 deletions modules/app_eks/lb_controller/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@ variable "oidc_provider" {
url = string
})
}

variable "aws_loadbalancer_controller_tags" {
type = map(string)
}
5 changes: 3 additions & 2 deletions modules/app_eks/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,9 @@ resource "aws_iam_openid_connect_provider" "eks" {
module "lb_controller" {
source = "./lb_controller"

namespace = var.namespace
oidc_provider = aws_iam_openid_connect_provider.eks
namespace = var.namespace
oidc_provider = aws_iam_openid_connect_provider.eks
aws_loadbalancer_controller_tags = var.aws_loadbalancer_controller_tags

depends_on = [module.eks]
}
Expand Down
6 changes: 6 additions & 0 deletions modules/app_eks/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -145,3 +145,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 = {}
}
6 changes: 6 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,12 @@ variable "system_reserved_pid" {
default = 500
}

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 = {}
}

##########################################
# External Bucket #
##########################################
Expand Down

0 comments on commit 74a2854

Please sign in to comment.