Skip to content

Add Tag Specification to the AWS Launch Template for EKS Node Groups

I would like to request the addition of the tag_specifications on the aws_launch_template for resource_type = instance.

Background

My team is being tasked with tagging all resource (as many as possible) with a cost tag. Currently, tagging looks relatively good with the exception of the EC2 instances associated with EKS Node Groups.

While the Node Groups have a tag attribute on them in terraform, they are only for tagging the EKS Node Group resource itself and not the underlying instances. The only way to apply tags to the instances backing the Node Group is to use a launch template (which is being done in GET) and specifying the tag_specifications attribute (not currently being done).

Solution

The following aws_launch_template resources can be modified:

The resource could be modified to include the following:

resource "aws_launch_template" "<template_name>" {
...
  tag_specifications {
    resource_type = "instance"

    tags = merge({
      gitlab_node_prefix = var.prefix
      gitlab_node_type   = "<type>-pool"

      "k8s.io/cluster-autoscaler/${aws_eks_cluster.gitlab_cluster[0].name}" = "owned"
      "k8s.io/cluster-autoscaler/enabled"                                   = "TRUE"
    }, var.additional_tags)
  }
...
}

I believe this change is the actual intention of the tags that are on the aws_eks_node_group resources themselves.

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information