From 94033d396a888cf130ed2919ddc72a132e2a52e1 Mon Sep 17 00:00:00 2001 From: Nikita Meschanenko Date: Thu, 2 Sep 2021 16:12:31 +0300 Subject: [PATCH 1/3] feat: Add ability to tag network-interface using Launch Template --- modules/node_groups/launch_template.tf | 14 ++++++++++++++ workers_launch_template.tf | 18 ++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/modules/node_groups/launch_template.tf b/modules/node_groups/launch_template.tf index f70d2f5838..7fc1e5f95c 100644 --- a/modules/node_groups/launch_template.tf +++ b/modules/node_groups/launch_template.tf @@ -103,6 +103,20 @@ resource "aws_launch_template" "workers" { ) } + # Supplying custom tags to EKS instances ENI's is another use-case for LaunchTemplates + tag_specifications { + resource_type = "network-interface" + + tags = merge( + var.tags, + { + Name = local.node_groups_names[each.key] + }, + lookup(var.node_groups_defaults, "additional_tags", {}), + lookup(var.node_groups[each.key], "additional_tags", {}) + ) + } + # Tag the LT itself tags = merge( var.tags, diff --git a/workers_launch_template.tf b/workers_launch_template.tf index d1d48186c0..62ded7caef 100644 --- a/workers_launch_template.tf +++ b/workers_launch_template.tf @@ -573,6 +573,24 @@ resource "aws_launch_template" "workers_launch_template" { ) } + tag_specifications { + resource_type = "network-interface" + + tags = merge( + { + "Name" = "${coalescelist(aws_eks_cluster.this[*].name, [""])[0]}-${lookup( + var.worker_groups_launch_template[count.index], + "name", + count.index, + )}-eks_asg" + }, + { for tag_key, tag_value in var.tags : + tag_key => tag_value + if tag_key != "Name" && !contains([for tag in lookup(var.worker_groups_launch_template[count.index], "tags", local.workers_group_defaults["tags"]) : tag["key"]], tag_key) + } + ) + } + tags = var.tags lifecycle { From 7c4082887b6f46390210fe2215c70d90e4cb79ed Mon Sep 17 00:00:00 2001 From: Nikita Meschanenko Date: Thu, 2 Sep 2021 20:28:57 +0300 Subject: [PATCH 2/3] feat: Update launch template with managed node group example --- .../launchtemplate.tf | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/examples/launch_templates_with_managed_node_groups/launchtemplate.tf b/examples/launch_templates_with_managed_node_groups/launchtemplate.tf index e66bad1a9f..2494a7a688 100644 --- a/examples/launch_templates_with_managed_node_groups/launchtemplate.tf +++ b/examples/launch_templates_with_managed_node_groups/launchtemplate.tf @@ -80,6 +80,15 @@ resource "aws_launch_template" "default" { } } + # Supplying custom tags to EKS instances ENI's is another use-case for LaunchTemplates + tag_specifications { + resource_type = "network-interface" + + tags = { + CustomTag = "EKS example" + } + } + # Tag the LT itself tags = { CustomTag = "EKS example" From 4fab42f22a94ea2d3926c8d41094d5b251ef5729 Mon Sep 17 00:00:00 2001 From: Nikita Meschanenko Date: Sun, 5 Sep 2021 15:27:34 +0300 Subject: [PATCH 3/3] feat: add proper tags to ENIs in worker group launch template --- modules/node_groups/launch_template.tf | 12 ++++++------ workers_launch_template.tf | 8 +++++--- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/modules/node_groups/launch_template.tf b/modules/node_groups/launch_template.tf index 7fc1e5f95c..40bcf17713 100644 --- a/modules/node_groups/launch_template.tf +++ b/modules/node_groups/launch_template.tf @@ -108,12 +108,12 @@ resource "aws_launch_template" "workers" { resource_type = "network-interface" tags = merge( - var.tags, - { - Name = local.node_groups_names[each.key] - }, - lookup(var.node_groups_defaults, "additional_tags", {}), - lookup(var.node_groups[each.key], "additional_tags", {}) + var.tags, + { + Name = local.node_groups_names[each.key] + }, + lookup(var.node_groups_defaults, "additional_tags", {}), + lookup(var.node_groups[each.key], "additional_tags", {}) ) } diff --git a/workers_launch_template.tf b/workers_launch_template.tf index 62ded7caef..9da5a16d04 100644 --- a/workers_launch_template.tf +++ b/workers_launch_template.tf @@ -584,9 +584,11 @@ resource "aws_launch_template" "workers_launch_template" { count.index, )}-eks_asg" }, - { for tag_key, tag_value in var.tags : - tag_key => tag_value - if tag_key != "Name" && !contains([for tag in lookup(var.worker_groups_launch_template[count.index], "tags", local.workers_group_defaults["tags"]) : tag["key"]], tag_key) + var.tags, + { + for tag in lookup(var.worker_groups_launch_template[count.index], "tags", local.workers_group_defaults["tags"]) : + tag["key"] => tag["value"] + if tag["key"] != "Name" && tag["propagate_at_launch"] } ) }