diff --git a/src/_nebari/stages/infrastructure/template/aws/modules/kubernetes/main.tf b/src/_nebari/stages/infrastructure/template/aws/modules/kubernetes/main.tf index c2ed3cc4ae..a2238a41f8 100644 --- a/src/_nebari/stages/infrastructure/template/aws/modules/kubernetes/main.tf +++ b/src/_nebari/stages/infrastructure/template/aws/modules/kubernetes/main.tf @@ -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 - ] -} diff --git a/src/_nebari/stages/kubernetes_initialize/template/main.tf b/src/_nebari/stages/kubernetes_initialize/template/main.tf index 402c68fb3f..816d382692 100644 --- a/src/_nebari/stages/kubernetes_initialize/template/main.tf +++ b/src/_nebari/stages/kubernetes_initialize/template/main.tf @@ -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 +} \ No newline at end of file diff --git a/src/_nebari/stages/kubernetes_initialize/template/modules/tagging/aws-asg-tagging.tf b/src/_nebari/stages/kubernetes_initialize/template/modules/tagging/aws-asg-tagging.tf new file mode 100644 index 0000000000..27c30f786d --- /dev/null +++ b/src/_nebari/stages/kubernetes_initialize/template/modules/tagging/aws-asg-tagging.tf @@ -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, + ] +} diff --git a/src/_nebari/stages/kubernetes_initialize/template/modules/tagging/variables.tf b/src/_nebari/stages/kubernetes_initialize/template/modules/tagging/variables.tf new file mode 100644 index 0000000000..00b51c849f --- /dev/null +++ b/src/_nebari/stages/kubernetes_initialize/template/modules/tagging/variables.tf @@ -0,0 +1,4 @@ +variable "cluster_name" { + description = "Name of the cluster." + type = string +}