0
votes

I am using terraform 12.20.0 and I have provisioned an EKS cluster with 2 node groups.

How can I add name tags to EKS node workers according to their node group names?

I have tried adding "Name" tag in the additional tag sections of each node-group but the tags did not take and my EC2 instance names are empty, while other tags appear.

Here is the configuration - I have skipped the less relevant bits:

module "eks-cluster" {
...
  node_groups_defaults = {
    disk_size = 128
    key_name  = var.key_name
    subnets = [
      aws_subnet.{{}}.id,
      aws_subnet.{{}}.id,
    ]
    k8s_labels = {
      env = var.environment
    }

    additional_tags = {
      env                                             = var.environment
      "k8s.io/cluster-autoscaler/enabled"             = "true"
      "k8s.io/cluster-autoscaler/${var.cluster-name}" = "true"
    }
  }

  node_groups = {
    app = {
      name = "app"

      .....

      k8s_labels = {
        nodegroup = "app"
      }
      additional_tags = {
        nodegroup = "app"
        Name      = "${var.environment}-app-node"
      }
    }
    ml = {
      name = "ml"

     ...
      instance_type = "m5.xlarge"
      k8s_labels = {
        nodegroup = "ml"
      }
      additional_tags = {
        nodegroup = "ml"
        Name      = "${var.environment}-ml-node"
      }
    }
  }

  tags = {
    env = var.environment
  }

  map_roles = [{
    ......
  }]
}
2

2 Answers

1
votes

As per documentation Resource: aws_eks_node_group doesn't allow for modifying tags on your instances.

There is a nice feature coming soon to EKS node groups which will allow you to pass a custom userdata script. Using that you will be able to modify programatically tags for your instances. Issues can be tracked -> https://github.com/aws/containers-roadmap/issues/596

UPDATE: As of 20/08/2020, you can now utilise launch_template with your node group. This will allow you to pass in Name tag. Example:

resource "aws_launch_template" "cluster" {
  image_id               = data.aws_ssm_parameter.cluster.value
  instance_type          = "t3.medium"
  name                   = "eks-launch-template-test"
  update_default_version = true

  tag_specifications {
    resource_type = "instance"

    tags = {
      Name                        = "eks-node-group-instance-name"
    }
  }
} 
0
votes

I just noticed that

"k8s.io/cluster-autoscaler/${var.cluster-name}" = "true"

Might need to be

"k8s.io/cluster-autoscaler/${var.cluster-name}" = "owned"