From 236e76823155e6388dcf8abcdafbc67fb02ff791 Mon Sep 17 00:00:00 2001 From: kahirokunn Date: Thu, 3 Feb 2022 13:46:27 +0900 Subject: [PATCH 01/10] add launch_template_tag_specifications_tags option --- modules/eks-managed-node-group/main.tf | 2 +- modules/eks-managed-node-group/variables.tf | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/modules/eks-managed-node-group/main.tf b/modules/eks-managed-node-group/main.tf index bbe02105d2..a716fd542b 100644 --- a/modules/eks-managed-node-group/main.tf +++ b/modules/eks-managed-node-group/main.tf @@ -232,7 +232,7 @@ resource "aws_launch_template" "this" { for_each = toset(["instance", "volume", "network-interface"]) content { resource_type = tag_specifications.key - tags = merge(var.tags, { Name = var.name }) + tags = merge(var.tags, { Name = var.name }, var.launch_template_tag_specifications_tags) } } diff --git a/modules/eks-managed-node-group/variables.tf b/modules/eks-managed-node-group/variables.tf index ddefdcf655..b25c7ffb73 100644 --- a/modules/eks-managed-node-group/variables.tf +++ b/modules/eks-managed-node-group/variables.tf @@ -408,6 +408,12 @@ variable "security_group_tags" { default = {} } +variable "launch_template_tag_specifications_tags" { + description = "A map of additional tags to add to the tag_specifications of launch template created" + type = map(string) + default = {} +} + ################################################################################ # IAM Role ################################################################################ From 1dc864b30c1dca654251442e5f714fb24b9c1660 Mon Sep 17 00:00:00 2001 From: kahirokunn Date: Thu, 3 Feb 2022 21:33:38 +0900 Subject: [PATCH 02/10] Update modules/eks-managed-node-group/variables.tf Co-authored-by: Bryant Biggs --- modules/eks-managed-node-group/variables.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/eks-managed-node-group/variables.tf b/modules/eks-managed-node-group/variables.tf index b25c7ffb73..57fc64c3f2 100644 --- a/modules/eks-managed-node-group/variables.tf +++ b/modules/eks-managed-node-group/variables.tf @@ -408,7 +408,7 @@ variable "security_group_tags" { default = {} } -variable "launch_template_tag_specifications_tags" { +variable "launch_template_tags" { description = "A map of additional tags to add to the tag_specifications of launch template created" type = map(string) default = {} From af68ee9a31f36a87df47287e34b846ee3134de5d Mon Sep 17 00:00:00 2001 From: kahirokunn Date: Thu, 3 Feb 2022 21:35:09 +0900 Subject: [PATCH 03/10] change launch_template_tag_specifications_tags variable to launch_template_tags --- modules/eks-managed-node-group/main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/eks-managed-node-group/main.tf b/modules/eks-managed-node-group/main.tf index a716fd542b..0e2b6b54fe 100644 --- a/modules/eks-managed-node-group/main.tf +++ b/modules/eks-managed-node-group/main.tf @@ -232,7 +232,7 @@ resource "aws_launch_template" "this" { for_each = toset(["instance", "volume", "network-interface"]) content { resource_type = tag_specifications.key - tags = merge(var.tags, { Name = var.name }, var.launch_template_tag_specifications_tags) + tags = merge(var.tags, { Name = var.name }, var.launch_template_tags) } } From 57427b25ef3f4b8ba50eb561e603c871fa5f3aea Mon Sep 17 00:00:00 2001 From: kahirokunn Date: Thu, 3 Feb 2022 21:49:50 +0900 Subject: [PATCH 04/10] Declared launch template tags in the correct place. --- modules/eks-managed-node-group/variables.tf | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/modules/eks-managed-node-group/variables.tf b/modules/eks-managed-node-group/variables.tf index 57fc64c3f2..d176ff08d9 100644 --- a/modules/eks-managed-node-group/variables.tf +++ b/modules/eks-managed-node-group/variables.tf @@ -238,6 +238,12 @@ variable "placement" { default = null } +variable "launch_template_tags" { + description = "A map of additional tags to add to the tag_specifications of launch template created" + type = map(string) + default = {} +} + ################################################################################ # EKS Managed Node Group ################################################################################ @@ -408,12 +414,6 @@ variable "security_group_tags" { default = {} } -variable "launch_template_tags" { - description = "A map of additional tags to add to the tag_specifications of launch template created" - type = map(string) - default = {} -} - ################################################################################ # IAM Role ################################################################################ From dedb80597ae435ff37f5f842617eb1e2cf01477a Mon Sep 17 00:00:00 2001 From: kahirokunn Date: Thu, 3 Feb 2022 21:50:13 +0900 Subject: [PATCH 05/10] add launch_template_tags variable to self managed-node group --- modules/self-managed-node-group/main.tf | 2 +- modules/self-managed-node-group/variables.tf | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/modules/self-managed-node-group/main.tf b/modules/self-managed-node-group/main.tf index 8750892e3c..36bc428e7c 100644 --- a/modules/self-managed-node-group/main.tf +++ b/modules/self-managed-node-group/main.tf @@ -229,7 +229,7 @@ resource "aws_launch_template" "this" { for_each = toset(["instance", "volume", "network-interface"]) content { resource_type = tag_specifications.key - tags = merge(var.tags, { Name = var.name }) + tags = merge(var.tags, { Name = var.name }, var.launch_template_tags) } } diff --git a/modules/self-managed-node-group/variables.tf b/modules/self-managed-node-group/variables.tf index 7bcebeaddc..e9f8646a40 100644 --- a/modules/self-managed-node-group/variables.tf +++ b/modules/self-managed-node-group/variables.tf @@ -250,6 +250,12 @@ variable "metadata_options" { } } +variable "launch_template_tags" { + description = "A map of additional tags to add to the tag_specifications of launch template created" + type = map(string) + default = {} +} + ################################################################################ # Autoscaling group ################################################################################ From d520b04f64c31e1ff456b9aa12635ceaa1bc7085 Mon Sep 17 00:00:00 2001 From: kahirokunn Date: Thu, 3 Feb 2022 21:54:41 +0900 Subject: [PATCH 06/10] activate launch_template_tags --- node_groups.tf | 2 ++ 1 file changed, 2 insertions(+) diff --git a/node_groups.tf b/node_groups.tf index 0f98647b6e..5669bac7e9 100644 --- a/node_groups.tf +++ b/node_groups.tf @@ -296,6 +296,7 @@ module "eks_managed_node_group" { enable_monitoring = try(each.value.enable_monitoring, var.eks_managed_node_group_defaults.enable_monitoring, true) network_interfaces = try(each.value.network_interfaces, var.eks_managed_node_group_defaults.network_interfaces, []) placement = try(each.value.placement, var.eks_managed_node_group_defaults.placement, null) + launch_template_tags = try(each.value.launch_template_tags, var.eks_managed_node_group_defaults.launch_template_tags, null) # IAM role create_iam_role = try(each.value.create_iam_role, var.eks_managed_node_group_defaults.create_iam_role, true) @@ -418,6 +419,7 @@ module "self_managed_node_group" { enable_monitoring = try(each.value.enable_monitoring, var.self_managed_node_group_defaults.enable_monitoring, true) network_interfaces = try(each.value.network_interfaces, var.self_managed_node_group_defaults.network_interfaces, []) placement = try(each.value.placement, var.self_managed_node_group_defaults.placement, null) + launch_template_tags = try(each.value.launch_template_tags, var.self_managed_node_group_defaults.launch_template_tags, null) # IAM role create_iam_instance_profile = try(each.value.create_iam_instance_profile, var.self_managed_node_group_defaults.create_iam_instance_profile, true) From fab10843625ae2632c98c2463f5083c850ac8deb Mon Sep 17 00:00:00 2001 From: kahirokunn Date: Thu, 3 Feb 2022 22:11:07 +0900 Subject: [PATCH 07/10] pre-commit run terraform_docs -a --- modules/eks-managed-node-group/README.md | 1 + modules/self-managed-node-group/README.md | 1 + 2 files changed, 2 insertions(+) diff --git a/modules/eks-managed-node-group/README.md b/modules/eks-managed-node-group/README.md index 9605e7fef4..b53bf7f05f 100644 --- a/modules/eks-managed-node-group/README.md +++ b/modules/eks-managed-node-group/README.md @@ -129,6 +129,7 @@ module "eks_managed_node_group" { | [launch\_template\_default\_version](#input\_launch\_template\_default\_version) | Default version of the launch template | `string` | `null` | no | | [launch\_template\_description](#input\_launch\_template\_description) | Description of the launch template | `string` | `null` | no | | [launch\_template\_name](#input\_launch\_template\_name) | Launch template name - either to be created (`var.create_launch_template` = `true`) or existing (`var.create_launch_template` = `false`) | `string` | `""` | no | +| [launch\_template\_tags](#input\_launch\_template\_tags) | A map of additional tags to add to the tag\_specifications of launch template created | `map(string)` | `{}` | no | | [launch\_template\_use\_name\_prefix](#input\_launch\_template\_use\_name\_prefix) | Determines whether to use `launch_template_name` as is or create a unique name beginning with the `launch_template_name` as the prefix | `bool` | `true` | no | | [launch\_template\_version](#input\_launch\_template\_version) | Launch template version number. The default is `$Default` | `string` | `null` | no | | [license\_specifications](#input\_license\_specifications) | A list of license specifications to associate with | `map(string)` | `null` | no | diff --git a/modules/self-managed-node-group/README.md b/modules/self-managed-node-group/README.md index b1ff6b64fd..0d705f730e 100644 --- a/modules/self-managed-node-group/README.md +++ b/modules/self-managed-node-group/README.md @@ -128,6 +128,7 @@ module "self_managed_node_group" { | [launch\_template\_default\_version](#input\_launch\_template\_default\_version) | Default Version of the launch template | `string` | `null` | no | | [launch\_template\_description](#input\_launch\_template\_description) | Description of the launch template | `string` | `null` | no | | [launch\_template\_name](#input\_launch\_template\_name) | Launch template name - either to be created (`var.create_launch_template` = `true`) or existing (`var.create_launch_template` = `false`) | `string` | `null` | no | +| [launch\_template\_tags](#input\_launch\_template\_tags) | A map of additional tags to add to the tag\_specifications of launch template created | `map(string)` | `{}` | no | | [launch\_template\_use\_name\_prefix](#input\_launch\_template\_use\_name\_prefix) | Determines whether to use `launch_template_name` as is or create a unique name beginning with the `launch_template_name` as the prefix | `bool` | `true` | no | | [launch\_template\_version](#input\_launch\_template\_version) | Launch template version. Can be version number, `$Latest`, or `$Default` | `string` | `null` | no | | [license\_specifications](#input\_license\_specifications) | A list of license specifications to associate with | `map(string)` | `null` | no | From 52cfb324256074a55ab7ccc4bb402a40dfc774ea Mon Sep 17 00:00:00 2001 From: kahirokunn Date: Thu, 3 Feb 2022 22:45:44 +0900 Subject: [PATCH 08/10] refactor --- node_groups.tf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/node_groups.tf b/node_groups.tf index 5a2121f282..ed6ef95166 100644 --- a/node_groups.tf +++ b/node_groups.tf @@ -273,6 +273,7 @@ module "eks_managed_node_group" { launch_template_use_name_prefix = try(each.value.launch_template_use_name_prefix, var.eks_managed_node_group_defaults.launch_template_use_name_prefix, true) launch_template_version = try(each.value.launch_template_version, var.eks_managed_node_group_defaults.launch_template_version, null) launch_template_description = try(each.value.launch_template_description, var.eks_managed_node_group_defaults.launch_template_description, "Custom launch template for ${try(each.value.name, each.key)} EKS managed node group") + launch_template_tags = try(each.value.launch_template_tags, var.eks_managed_node_group_defaults.launch_template_tags, null) ebs_optimized = try(each.value.ebs_optimized, var.eks_managed_node_group_defaults.ebs_optimized, null) key_name = try(each.value.key_name, var.eks_managed_node_group_defaults.key_name, null) @@ -296,7 +297,6 @@ module "eks_managed_node_group" { enable_monitoring = try(each.value.enable_monitoring, var.eks_managed_node_group_defaults.enable_monitoring, true) network_interfaces = try(each.value.network_interfaces, var.eks_managed_node_group_defaults.network_interfaces, []) placement = try(each.value.placement, var.eks_managed_node_group_defaults.placement, null) - launch_template_tags = try(each.value.launch_template_tags, var.eks_managed_node_group_defaults.launch_template_tags, null) # IAM role create_iam_role = try(each.value.create_iam_role, var.eks_managed_node_group_defaults.create_iam_role, true) @@ -391,6 +391,7 @@ module "self_managed_node_group" { launch_template_use_name_prefix = try(each.value.launch_template_use_name_prefix, var.self_managed_node_group_defaults.launch_template_use_name_prefix, true) launch_template_version = try(each.value.launch_template_version, var.self_managed_node_group_defaults.launch_template_version, null) launch_template_description = try(each.value.launch_template_description, var.self_managed_node_group_defaults.launch_template_description, "Custom launch template for ${try(each.value.name, each.key)} self managed node group") + launch_template_tags = try(each.value.launch_template_tags, var.self_managed_node_group_defaults.launch_template_tags, null) ebs_optimized = try(each.value.ebs_optimized, var.self_managed_node_group_defaults.ebs_optimized, null) ami_id = try(each.value.ami_id, var.self_managed_node_group_defaults.ami_id, "") @@ -421,7 +422,6 @@ module "self_managed_node_group" { enable_monitoring = try(each.value.enable_monitoring, var.self_managed_node_group_defaults.enable_monitoring, true) network_interfaces = try(each.value.network_interfaces, var.self_managed_node_group_defaults.network_interfaces, []) placement = try(each.value.placement, var.self_managed_node_group_defaults.placement, null) - launch_template_tags = try(each.value.launch_template_tags, var.self_managed_node_group_defaults.launch_template_tags, null) # IAM role create_iam_instance_profile = try(each.value.create_iam_instance_profile, var.self_managed_node_group_defaults.create_iam_instance_profile, true) From d2cde13c7573de9047bc508614f0387a39203022 Mon Sep 17 00:00:00 2001 From: kahirokunn Date: Thu, 3 Feb 2022 23:29:13 +0900 Subject: [PATCH 09/10] Update node_groups.tf Co-authored-by: Bryant Biggs --- node_groups.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/node_groups.tf b/node_groups.tf index ed6ef95166..b6efa1b1f8 100644 --- a/node_groups.tf +++ b/node_groups.tf @@ -273,7 +273,7 @@ module "eks_managed_node_group" { launch_template_use_name_prefix = try(each.value.launch_template_use_name_prefix, var.eks_managed_node_group_defaults.launch_template_use_name_prefix, true) launch_template_version = try(each.value.launch_template_version, var.eks_managed_node_group_defaults.launch_template_version, null) launch_template_description = try(each.value.launch_template_description, var.eks_managed_node_group_defaults.launch_template_description, "Custom launch template for ${try(each.value.name, each.key)} EKS managed node group") - launch_template_tags = try(each.value.launch_template_tags, var.eks_managed_node_group_defaults.launch_template_tags, null) + launch_template_tags = try(each.value.launch_template_tags, var.eks_managed_node_group_defaults.launch_template_tags, {}) ebs_optimized = try(each.value.ebs_optimized, var.eks_managed_node_group_defaults.ebs_optimized, null) key_name = try(each.value.key_name, var.eks_managed_node_group_defaults.key_name, null) From e3d9035557eb782be8f1545ec4ca513684a3e2ea Mon Sep 17 00:00:00 2001 From: kahirokunn Date: Thu, 3 Feb 2022 23:29:19 +0900 Subject: [PATCH 10/10] Update node_groups.tf Co-authored-by: Bryant Biggs --- node_groups.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/node_groups.tf b/node_groups.tf index b6efa1b1f8..0381005a24 100644 --- a/node_groups.tf +++ b/node_groups.tf @@ -391,7 +391,7 @@ module "self_managed_node_group" { launch_template_use_name_prefix = try(each.value.launch_template_use_name_prefix, var.self_managed_node_group_defaults.launch_template_use_name_prefix, true) launch_template_version = try(each.value.launch_template_version, var.self_managed_node_group_defaults.launch_template_version, null) launch_template_description = try(each.value.launch_template_description, var.self_managed_node_group_defaults.launch_template_description, "Custom launch template for ${try(each.value.name, each.key)} self managed node group") - launch_template_tags = try(each.value.launch_template_tags, var.self_managed_node_group_defaults.launch_template_tags, null) + launch_template_tags = try(each.value.launch_template_tags, var.self_managed_node_group_defaults.launch_template_tags, {}) ebs_optimized = try(each.value.ebs_optimized, var.self_managed_node_group_defaults.ebs_optimized, null) ami_id = try(each.value.ami_id, var.self_managed_node_group_defaults.ami_id, "")