Skip to content

Commit

Permalink
Add a module for ASG tagging at 03-kubernetes-initialize/aws-asg-tagg…
Browse files Browse the repository at this point in the history
…ing.
  • Loading branch information
Prashant Tiwari committed Jan 7, 2024
1 parent 7996faa commit 7c9f6ec
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,55 +95,3 @@ resource "aws_iam_openid_connect_provider" "oidc_provider" {
var.tags
)
}
data "aws_eks_node_group" "user" {
cluster_name = aws_eks_cluster.main.name
node_group_name = "user"
depends_on = [
aws_eks_node_group.main
]
}

resource "aws_autoscaling_group_tag" "dedicated_user" {
for_each = toset(
[for asg in flatten(
[for resources in data.aws_eks_node_group.user.resources : resources.autoscaling_groups]
) : asg.name]
)

autoscaling_group_name = each.value
tag {
key = "k8s.io/cluster-autoscaler/node-template/label/dedicated"
value = "user"
propagate_at_launch = true
}
depends_on = [
aws_eks_node_group.main,
data.aws_eks_node_group.user
]
}

data "aws_eks_node_group" "worker" {
cluster_name = aws_eks_cluster.main.name
node_group_name = "worker"
depends_on = [
aws_eks_node_group.main
]
}

resource "aws_autoscaling_group_tag" "dedicated_worker" {
for_each = toset(
[for asg in flatten(
[for resources in data.aws_eks_node_group.worker.resources : resources.autoscaling_groups]
) : asg.name]
)
autoscaling_group_name = each.value
tag {
key = "k8s.io/cluster-autoscaler/node-template/label/dedicated"
value = "worker"
propagate_at_launch = true
}
depends_on = [
data.aws_eks_node_group.worker,
aws_eks_node_group.main
]
}
6 changes: 6 additions & 0 deletions src/_nebari/stages/kubernetes_initialize/template/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,9 @@ module "nvidia-driver-installer" {
gpu_enabled = var.gpu_enabled
gpu_node_group_names = var.gpu_node_group_names
}

module "tagging" {
count = var.cloud_provider == "aws" ? 1 : 0
source = "./modules/tagging"
cluster_name = local.cluster_name
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
data "aws_eks_node_group" "user" {
cluster_name = var.cluster_name
node_group_name = "user"
}

resource "aws_autoscaling_group_tag" "dedicated_user" {
for_each = toset(
[for asg in flatten(
[for resources in data.aws_eks_node_group.user.resources : resources.autoscaling_groups]
) : asg.name]
)

autoscaling_group_name = each.value
tag {
key = "k8s.io/cluster-autoscaler/node-template/label/dedicated"
value = "user"
propagate_at_launch = true
}
depends_on = [
data.aws_eks_node_group.user
]
}

data "aws_eks_node_group" "worker" {
cluster_name = var.cluster_name
node_group_name = "worker"
}

resource "aws_autoscaling_group_tag" "dedicated_worker" {
for_each = toset(
[for asg in flatten(
[for resources in data.aws_eks_node_group.worker.resources : resources.autoscaling_groups]
) : asg.name]
)
autoscaling_group_name = each.value
tag {
key = "k8s.io/cluster-autoscaler/node-template/label/dedicated"
value = "worker"
propagate_at_launch = true
}
depends_on = [
data.aws_eks_node_group.worker,
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
variable "cluster_name" {
description = "Name of the cluster."
type = string
}

0 comments on commit 7c9f6ec

Please sign in to comment.