This template manages tags for Autoscaling Groups created by an EKS Node Group, specifically setting a label for the cluster autoscaler.

Terraform Template

resource "aws_autoscaling_group_tag" "example" {
  autoscaling_group_name = each.value
  for_each = toset(
 [for asg in flatten(
 [for resources in aws_eks_node_group.example.resources : resources.autoscaling_groups]
 ) : asg.name]
 )

  tag {
    key = "k8s.io/cluster-autoscaler/node-template/label/eks.amazonaws.com/capacityType"
    propagate_at_launch = false
    value = "SPOT"
  }
}

resource "aws_eks_node_group" "example" {
  cluster_name = "example"
  node_group_name = "example"
}