From f203c881f06451dd3db287f4c0c3779950bbdceb Mon Sep 17 00:00:00 2001
From: Pauline
Date: Tue, 20 Apr 2021 14:36:15 +0200
Subject: [PATCH] Fix: add custom tags on managed node's ASG (fixes scale-up by
the autoscaler)
The tags specified on the resource type "aws_eks_node_group" are not propagated to the ASG that represents this node group (issue https://github.com/aws/containers-roadmap/issues/608).
As a workaround, we add tags to the ASG after the nodegroup creation/updates using the AWS command-line.
This will fix scaling up from 0, in EKS-managed node groups, when pods
have affinities/nodeSelectors defined on custom tags.
---
kubernetes.tf | 39 +++++++++++++++++++++++++++++++++++++++
versions.tf | 1 +
2 files changed, 40 insertions(+)
diff --git a/kubernetes.tf b/kubernetes.tf
index a998208..f1d8dcc 100644
--- a/kubernetes.tf
+++ b/kubernetes.tf
@@ -103,6 +103,45 @@ resource "aws_eks_node_group" "quortex" {
]
}
+# This datasource is used to get the region currently used by the AWS provider
+data "aws_region" "current" {
+}
+
+# This AWS CLI command will add tags to the ASG created by EKS
+#
+# The tags specified on the resource type "aws_eks_node_group" are not propagated to the ASG that
+# represents this node group (issue https://github.com/aws/containers-roadmap/issues/608).
+#
+# As a workaround, we add tags to the ASG after the nodegroup creation/updates using the AWS
+# command-line.
+#
+# Thanks to the PropagateAtLaunch=true argument, these tags will also be propagated to instances
+# created in this ASG.
+#
+# Note: on tag updates, the command will not be run again (the command is triggered by changes in
+# the ASG name). The tags update can be forced by the terraform command:
+# terraform taint module.eks.null_resource.add_custom_tags_to_asg[\"main\"]
+resource "null_resource" "add_custom_tags_to_asg" {
+ for_each = aws_eks_node_group.quortex
+
+ triggers = {
+ node_group = each.value["resources"][0]["autoscaling_groups"][0]["name"]
+ }
+
+ provisioner "local-exec" {
+ command = <