diff --git a/modules/node_groups/README.md b/modules/node_groups/README.md index c9bcab0d4ed..bdcadff8c6a 100644 --- a/modules/node_groups/README.md +++ b/modules/node_groups/README.md @@ -32,7 +32,8 @@ The role ARN specified in `var.default_iam_role_arn` will be used by default. In | launch\_template_version | The version of the LT to use | string | none | | max\_capacity | Max number of workers | number | `var.workers_group_defaults[asg_max_size]` | | min\_capacity | Min number of workers | number | `var.workers_group_defaults[asg_min_size]` | -| name | Name of the node group | string | Auto generated | +| name | Name of the node group | string | Will use autogenerate name prefix | +| name_prefix | Name prefix of the node group | string | Auto generated | | source\_security\_group\_ids | Source security groups for remote access to workers | list(string) | If key\_name is specified: THE REMOTE ACCESS WILL BE OPENED TO THE WORLD | | subnets | Subnets to contain workers | list(string) | `var.workers_group_defaults[subnets]` | | version | Kubernetes version | string | Provider default behavior | diff --git a/modules/node_groups/launchtemplate.tf b/modules/node_groups/launchtemplate.tf index 43e2e9ea6fa..2233e6025b0 100644 --- a/modules/node_groups/launchtemplate.tf +++ b/modules/node_groups/launchtemplate.tf @@ -23,7 +23,8 @@ data "cloudinit_config" "workers_userdata" { # Trivia: AWS transparently creates a copy of your LaunchTemplate and actually uses that copy then for the node group. If you DONT use a custom AMI, # then the default user-data for bootstrapping a cluster is merged in the copy. resource "aws_launch_template" "workers" { - for_each = { for k, v in local.node_groups_expanded : k => v if v["create_launch_template"] } + for_each = { for k, v in local.node_groups_expanded : k => v if v["create_launch_template"] } + name_prefix = lookup(each.value, "name", join("-", [var.cluster_name, each.key])) description = lookup(each.value, "name", join("-", [var.cluster_name, each.key])) update_default_version = true diff --git a/modules/node_groups/node_groups.tf b/modules/node_groups/node_groups.tf index 0dd46032519..8dfe75dcb67 100644 --- a/modules/node_groups/node_groups.tf +++ b/modules/node_groups/node_groups.tf @@ -1,10 +1,12 @@ resource "aws_eks_node_group" "workers" { for_each = local.node_groups_expanded - node_group_name_prefix = lookup(each.value, "name", join("-", [var.cluster_name, each.key])) - cluster_name = var.cluster_name - node_role_arn = each.value["iam_role_arn"] - subnet_ids = each.value["subnets"] + node_group_name_prefix = lookup(each.value, "name", null) == null ? lookup(each.value, "name_prefix", join("-", [var.cluster_name, each.key])) : null + node_group_name = lookup(each.value, "name", null) + + cluster_name = var.cluster_name + node_role_arn = each.value["iam_role_arn"] + subnet_ids = each.value["subnets"] scaling_config { desired_size = each.value["desired_capacity"]