From 094ed1d5e461552a0a76bc019c36690fe0fc2dd5 Mon Sep 17 00:00:00 2001 From: Bryant Biggs Date: Mon, 19 Dec 2022 13:50:32 -0500 Subject: [PATCH] feat: Allow configuring which tags are passed on launch template tag specifications (#2360) Resolves undefined --- modules/eks-managed-node-group/README.md | 1 + modules/eks-managed-node-group/main.tf | 2 +- modules/eks-managed-node-group/variables.tf | 6 ++++++ modules/self-managed-node-group/README.md | 1 + modules/self-managed-node-group/main.tf | 2 +- modules/self-managed-node-group/variables.tf | 6 ++++++ node_groups.tf | 2 ++ 7 files changed, 18 insertions(+), 2 deletions(-) diff --git a/modules/eks-managed-node-group/README.md b/modules/eks-managed-node-group/README.md index f05c31d5f6..9a47d03b31 100644 --- a/modules/eks-managed-node-group/README.md +++ b/modules/eks-managed-node-group/README.md @@ -161,6 +161,7 @@ module "eks_managed_node_group" { | [ram\_disk\_id](#input\_ram\_disk\_id) | The ID of the ram disk | `string` | `null` | no | | [remote\_access](#input\_remote\_access) | Configuration block with remote access settings. Only valid when `use_custom_launch_template` = `false` | `any` | `{}` | no | | [subnet\_ids](#input\_subnet\_ids) | Identifiers of EC2 Subnets to associate with the EKS Node Group. These subnets must have the following resource tag: `kubernetes.io/cluster/CLUSTER_NAME` | `list(string)` | `null` | no | +| [tag\_specifications](#input\_tag\_specifications) | The tags to apply to the resources during launch | `list(string)` |
[
"instance",
"volume",
"network-interface",
"spot-instances-request"
]
| no | | [tags](#input\_tags) | A map of tags to add to all resources | `map(string)` | `{}` | no | | [taints](#input\_taints) | The Kubernetes taints to be applied to the nodes in the node group. Maximum of 50 taints per node group | `any` | `{}` | no | | [timeouts](#input\_timeouts) | Create, update, and delete timeout configurations for the node group | `map(string)` | `{}` | no | diff --git a/modules/eks-managed-node-group/main.tf b/modules/eks-managed-node-group/main.tf index c59d553f19..dba2b58b5a 100644 --- a/modules/eks-managed-node-group/main.tf +++ b/modules/eks-managed-node-group/main.tf @@ -270,7 +270,7 @@ resource "aws_launch_template" "this" { ram_disk_id = var.ram_disk_id dynamic "tag_specifications" { - for_each = toset(["instance", "volume", "elastic-gpu", "network-interface", "spot-instances-request"]) + for_each = toset(var.tag_specifications) content { resource_type = tag_specifications.key diff --git a/modules/eks-managed-node-group/variables.tf b/modules/eks-managed-node-group/variables.tf index d2790e1acb..a2ef88f2c5 100644 --- a/modules/eks-managed-node-group/variables.tf +++ b/modules/eks-managed-node-group/variables.tf @@ -274,6 +274,12 @@ variable "launch_template_tags" { default = {} } +variable "tag_specifications" { + description = "The tags to apply to the resources during launch" + type = list(string) + default = ["instance", "volume", "network-interface", "spot-instances-request"] +} + ################################################################################ # EKS Managed Node Group ################################################################################ diff --git a/modules/self-managed-node-group/README.md b/modules/self-managed-node-group/README.md index f16a2514ea..89c86a507f 100644 --- a/modules/self-managed-node-group/README.md +++ b/modules/self-managed-node-group/README.md @@ -161,6 +161,7 @@ module "self_managed_node_group" { | [service\_linked\_role\_arn](#input\_service\_linked\_role\_arn) | The ARN of the service-linked role that the ASG will use to call other AWS services | `string` | `null` | no | | [subnet\_ids](#input\_subnet\_ids) | A list of subnet IDs to launch resources in. Subnets automatically determine which availability zones the group will reside. Conflicts with `availability_zones` | `list(string)` | `null` | no | | [suspended\_processes](#input\_suspended\_processes) | A list of processes to suspend for the Auto Scaling Group. The allowed values are `Launch`, `Terminate`, `HealthCheck`, `ReplaceUnhealthy`, `AZRebalance`, `AlarmNotification`, `ScheduledActions`, `AddToLoadBalancer`. Note that if you suspend either the `Launch` or `Terminate` process types, it can prevent your Auto Scaling Group from functioning properly | `list(string)` | `[]` | no | +| [tag\_specifications](#input\_tag\_specifications) | The tags to apply to the resources during launch | `list(string)` |
[
"instance",
"volume",
"network-interface",
"spot-instances-request"
]
| no | | [tags](#input\_tags) | A map of tags to add to all resources | `map(string)` | `{}` | no | | [target\_group\_arns](#input\_target\_group\_arns) | A set of `aws_alb_target_group` ARNs, for use with Application or Network Load Balancing | `list(string)` | `[]` | no | | [termination\_policies](#input\_termination\_policies) | A list of policies to decide how the instances in the Auto Scaling Group should be terminated. The allowed values are `OldestInstance`, `NewestInstance`, `OldestLaunchConfiguration`, `ClosestToNextInstanceHour`, `OldestLaunchTemplate`, `AllocationStrategy`, `Default` | `list(string)` | `[]` | no | diff --git a/modules/self-managed-node-group/main.tf b/modules/self-managed-node-group/main.tf index 10752fb769..7ba6fe6e30 100644 --- a/modules/self-managed-node-group/main.tf +++ b/modules/self-managed-node-group/main.tf @@ -364,7 +364,7 @@ resource "aws_launch_template" "this" { ram_disk_id = var.ram_disk_id dynamic "tag_specifications" { - for_each = toset(["instance", "volume", "elastic-gpu", "network-interface", "spot-instances-request"]) + for_each = toset(var.tag_specifications) content { resource_type = tag_specifications.key diff --git a/modules/self-managed-node-group/variables.tf b/modules/self-managed-node-group/variables.tf index c2850b659e..b158d5dd2f 100644 --- a/modules/self-managed-node-group/variables.tf +++ b/modules/self-managed-node-group/variables.tf @@ -286,6 +286,12 @@ variable "launch_template_tags" { default = {} } +variable "tag_specifications" { + description = "The tags to apply to the resources during launch" + type = list(string) + default = ["instance", "volume", "network-interface", "spot-instances-request"] +} + ################################################################################ # Autoscaling group ################################################################################ diff --git a/node_groups.tf b/node_groups.tf index 65403300b3..fa79b2696a 100644 --- a/node_groups.tf +++ b/node_groups.tf @@ -297,6 +297,7 @@ module "eks_managed_node_group" { update_launch_template_default_version = try(each.value.update_launch_template_default_version, var.eks_managed_node_group_defaults.update_launch_template_default_version, true) 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, {}) + tag_specifications = try(each.value.tag_specifications, var.eks_managed_node_group_defaults.tag_specifications, ["instance", "volume", "network-interface", "spot-instances-request"]) 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) @@ -422,6 +423,7 @@ module "self_managed_node_group" { update_launch_template_default_version = try(each.value.update_launch_template_default_version, var.self_managed_node_group_defaults.update_launch_template_default_version, true) 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, {}) + tag_specifications = try(each.value.tag_specifications, var.eks_managed_node_group_defaults.tag_specifications, ["instance", "volume", "network-interface", "spot-instances-request"]) 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, "")