Skip to content

Commit 9b1bf2a

Browse files
committed
Supports toggling eks auto mode on and off
The API has a number of constraints that make this a litle difficult, but it does work. 1. The node_role_arn cannot be changed without recreating the cluster. This is an API limitation, not a terraform provider bug. https://docs.aws.amazon.com/eks/latest/APIReference/API_ComputeConfigRequest.html 2. If node_pools is not empty, then the node_role_arn *must* be provided. 3. If the node_role_arn is provided, then node_pools must not be empty! If you enable Auto Mode and set node_pools to a non-empty value, which requires setting node_role_arn, you cannot later change node_pools to an empty value, unless you also unset the node_role_arn. But if you unset the node_role_arn, then the cluster will be recreated due to the first point above. So, we *can* support disabling auto-mode without recreating a cluster, but only if node_pools is not empty and if node_role_arn does not change. Fixes terraform-aws-modules#3273
1 parent 44cf663 commit 9b1bf2a

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

examples/eks-auto-mode/main.tf

+4
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ module "eks" {
3838

3939
enable_cluster_creator_admin_permissions = true
4040

41+
# Set `bootstrap_self_managed_addons` to false to support disabling auto mode,
42+
# without recreating the cluster
43+
bootstrap_self_managed_addons = false
44+
4145
cluster_compute_config = {
4246
enabled = true
4347
node_pools = ["general-purpose"]

main.tf

+3-3
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ resource "aws_eks_cluster" "this" {
5757

5858
content {
5959
enabled = local.auto_mode_enabled
60-
node_pools = local.auto_mode_enabled ? try(compute_config.value.node_pools, []) : null
61-
node_role_arn = local.auto_mode_enabled && length(try(compute_config.value.node_pools, [])) > 0 ? try(compute_config.value.node_role_arn, aws_iam_role.eks_auto[0].arn, null) : null
60+
node_pools = try(compute_config.value.node_pools, [])
61+
node_role_arn = length(try(compute_config.value.node_pools, [])) > 0 ? try(compute_config.value.node_role_arn, aws_iam_role.eks_auto[0].arn, null) : null
6262
}
6363
}
6464

@@ -848,7 +848,7 @@ resource "aws_eks_identity_provider_config" "this" {
848848
################################################################################
849849

850850
locals {
851-
create_node_iam_role = local.create && var.create_node_iam_role && local.auto_mode_enabled
851+
create_node_iam_role = local.create && var.create_node_iam_role
852852
node_iam_role_name = coalesce(var.node_iam_role_name, "${var.cluster_name}-eks-auto")
853853
}
854854

0 commit comments

Comments
 (0)