Skip to content

Commit 7d61faf

Browse files
adrientheboroboquat
authored andcommitted
[install/infra] truncate EKS service node group to 58 chars + random suffix
EKS limits [iam role prefix lengths] to 38 characters, as the IAM role length max is 64 characters and the random 26 character suffix eats up most of the string length. As we're naming our clusters based on the current branch these names could become quite long. This commit removes this issue by creating a specific IAM role name and creating our own unique IDs. [iam role prefix lengths]: https://github.com/hashicorp/terraform-provider-aws/blob/v4.27.0/internal/service/iam/role.go#L29-L30
1 parent 1b914e6 commit 7d61faf

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

install/infra/modules/eks/kubernetes.tf

+10
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,13 @@ resource "aws_security_group" "nodes" {
6464
}
6565
}
6666

67+
resource "random_string" "ng_role_suffix" {
68+
upper = false
69+
lower = true
70+
special = false
71+
length = 4
72+
}
73+
6774
module "eks" {
6875
source = "terraform-aws-modules/eks/aws"
6976
version = "18.8.1"
@@ -91,6 +98,7 @@ module "eks" {
9198
eks_managed_node_group_defaults = {
9299
ami_type = "CUSTOM"
93100
iam_role_attach_cni_policy = true
101+
iam_role_use_name_prefix = false
94102
ami_id = var.image_id
95103
enable_bootstrap_user_data = true
96104
vpc_security_group_ids = [aws_security_group.nodes.id]
@@ -102,6 +110,7 @@ module "eks" {
102110
enable_bootstrap_user_data = true
103111
instance_types = [var.service_machine_type]
104112
name = "service-${var.cluster_name}"
113+
iam_role_name = format("%s-%s", substr("${var.cluster_name}-svc-ng", 0, 58), random_string.ng_role_suffix.result)
105114
subnet_ids = module.vpc.public_subnets
106115
min_size = 1
107116
max_size = 4
@@ -142,6 +151,7 @@ module "eks" {
142151
Workspaces = {
143152
instance_types = [var.workspace_machine_type]
144153
name = "ws-${var.cluster_name}"
154+
iam_role_name = format("%s-%s", substr("${var.cluster_name}-ws-ng", 0, 58), random_string.ng_role_suffix.result)
145155
subnet_ids = module.vpc.public_subnets
146156
min_size = 1
147157
max_size = 50

0 commit comments

Comments
 (0)