Skip to content

Commit e2846be

Browse files
authored
fix: Create EKS Auto Mode role when Auto Mode is enabled, regardless of built-in node pool use (#3234)
1 parent 6168518 commit e2846be

File tree

2 files changed

+19
-23
lines changed

2 files changed

+19
-23
lines changed

examples/karpenter/main.tf

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -95,16 +95,6 @@ module "eks" {
9595
min_size = 2
9696
max_size = 3
9797
desired_size = 2
98-
99-
taints = {
100-
# This Taint aims to keep just EKS Addons and Karpenter running on this MNG
101-
# The pods that do not tolerate this taint should run on nodes created by Karpenter
102-
addons = {
103-
key = "CriticalAddonsOnly"
104-
value = "true"
105-
effect = "NO_SCHEDULE"
106-
},
107-
}
10898
}
10999
}
110100

@@ -164,17 +154,18 @@ resource "helm_release" "karpenter" {
164154
repository_username = data.aws_ecrpublic_authorization_token.token.user_name
165155
repository_password = data.aws_ecrpublic_authorization_token.token.password
166156
chart = "karpenter"
167-
version = "1.0.6"
157+
version = "1.1.0"
168158
wait = false
169159

170160
values = [
171161
<<-EOT
172-
serviceAccount:
173-
name: ${module.karpenter.service_account}
162+
dnsPolicy: Default
174163
settings:
175164
clusterName: ${module.eks.cluster_name}
176165
clusterEndpoint: ${module.eks.cluster_endpoint}
177166
interruptionQueue: ${module.karpenter.queue_name}
167+
webhook:
168+
enabled: false
178169
EOT
179170
]
180171
}
@@ -226,7 +217,7 @@ resource "kubectl_manifest" "karpenter_node_pool" {
226217
values: ["nitro"]
227218
- key: "karpenter.k8s.aws/instance-generation"
228219
operator: Gt
229-
values: ["2"]
220+
values: ["5"]
230221
limits:
231222
cpu: 1000
232223
disruption:

main.tf

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,31 @@
1-
data "aws_partition" "current" {}
2-
data "aws_caller_identity" "current" {}
1+
data "aws_partition" "current" {
2+
count = local.create ? 1 : 0
3+
}
4+
data "aws_caller_identity" "current" {
5+
count = local.create ? 1 : 0
6+
}
37

48
data "aws_iam_session_context" "current" {
9+
count = local.create ? 1 : 0
10+
511
# This data source provides information on the IAM source role of an STS assumed role
612
# For non-role ARNs, this data source simply passes the ARN through issuer ARN
713
# Ref https://github.com/terraform-aws-modules/terraform-aws-eks/issues/2327#issuecomment-1355581682
814
# Ref https://github.com/hashicorp/terraform-provider-aws/issues/28381
9-
arn = data.aws_caller_identity.current.arn
15+
arn = try(data.aws_caller_identity.current[0].arn, "")
1016
}
1117

1218
locals {
1319
create = var.create && var.putin_khuylo
1420

15-
partition = data.aws_partition.current.partition
21+
partition = try(data.aws_partition.current[0].partition, "")
1622

1723
cluster_role = try(aws_iam_role.this[0].arn, var.iam_role_arn)
1824

1925
create_outposts_local_cluster = length(var.outpost_config) > 0
2026
enable_cluster_encryption_config = length(var.cluster_encryption_config) > 0 && !local.create_outposts_local_cluster
2127

22-
auto_mode_enabled = try(var.cluster_compute_config.enabled, false)
23-
auto_mode_nodepools_enabled = length(try(var.cluster_compute_config.node_pools, [])) > 0
28+
auto_mode_enabled = try(var.cluster_compute_config.enabled, false)
2429
}
2530

2631
################################################################################
@@ -218,7 +223,7 @@ locals {
218223
# better controlled by users through Terraform
219224
bootstrap_cluster_creator_admin_permissions = {
220225
cluster_creator = {
221-
principal_arn = data.aws_iam_session_context.current.issuer_arn
226+
principal_arn = try(data.aws_iam_session_context.current[0].issuer_arn, "")
222227
type = "STANDARD"
223228

224229
policy_associations = {
@@ -307,7 +312,7 @@ module "kms" {
307312
# Policy
308313
enable_default_policy = var.kms_key_enable_default_policy
309314
key_owners = var.kms_key_owners
310-
key_administrators = coalescelist(var.kms_key_administrators, [data.aws_iam_session_context.current.issuer_arn])
315+
key_administrators = coalescelist(var.kms_key_administrators, [try(data.aws_iam_session_context.current[0].issuer_arn, "")])
311316
key_users = concat([local.cluster_role], var.kms_key_users)
312317
key_service_users = var.kms_key_service_users
313318
source_policy_documents = var.kms_key_source_policy_documents
@@ -689,7 +694,7 @@ resource "aws_eks_identity_provider_config" "this" {
689694
################################################################################
690695

691696
locals {
692-
create_node_iam_role = local.create && var.create_node_iam_role && local.auto_mode_nodepools_enabled
697+
create_node_iam_role = local.create && var.create_node_iam_role && local.auto_mode_enabled
693698
node_iam_role_name = coalesce(var.node_iam_role_name, "${var.cluster_name}-eks-auto")
694699

695700
create_node_iam_role_custom_policy = local.create_node_iam_role && (var.enable_node_custom_tags_permissions || length(var.node_iam_role_policy_statements) > 0)

0 commit comments

Comments
 (0)