diff --git a/README.md b/README.md index ec22fdd351..7cafbf86c0 100644 --- a/README.md +++ b/README.md @@ -393,7 +393,7 @@ We are grateful to the community for contributing bugfixes and improvements! Ple | [cloudwatch\_log\_group\_retention\_in\_days](#input\_cloudwatch\_log\_group\_retention\_in\_days) | Number of days to retain log events. Default retention - 90 days | `number` | `90` | no | | [cloudwatch\_log\_group\_tags](#input\_cloudwatch\_log\_group\_tags) | A map of additional tags to add to the cloudwatch log group created | `map(string)` | `{}` | no | | [cluster\_tags](#input\_cluster\_tags) | A map of additional tags to add to the cluster | `map(string)` | `{}` | no | -| [compute\_config](#input\_compute\_config) | Configuration block for the cluster compute configuration |
object({
enabled = optional(bool, false)
node_pools = optional(list(string))
node_role_arn = optional(string)
})
| `null` | no | +| [compute\_config](#input\_compute\_config) | Configuration block for the cluster compute configuration |
object({
enabled = optional(bool, false)
node_pools = optional(list(string), [])
node_role_arn = optional(string)
})
| `null` | no | | [control\_plane\_subnet\_ids](#input\_control\_plane\_subnet\_ids) | A list of subnet IDs where the EKS cluster control plane (ENIs) will be provisioned. Used for expanding the pool of subnets used by nodes/node groups without replacing the EKS control plane | `list(string)` | `[]` | no | | [create](#input\_create) | Controls if resources should be created (affects nearly all resources) | `bool` | `true` | no | | [create\_cloudwatch\_log\_group](#input\_create\_cloudwatch\_log\_group) | Determines whether a log group is created by this module for the cluster logs. If not, AWS will automatically create one if logging is enabled | `bool` | `true` | no | diff --git a/examples/eks-auto-mode/README.md b/examples/eks-auto-mode/README.md index 204fecd0b4..efc9628509 100644 --- a/examples/eks-auto-mode/README.md +++ b/examples/eks-auto-mode/README.md @@ -39,6 +39,7 @@ Note that this example may create resources which cost money. Run `terraform des |------|--------|---------| | [disabled\_eks](#module\_disabled\_eks) | ../.. | n/a | | [eks](#module\_eks) | ../.. | n/a | +| [eks\_custom\_node\_pools](#module\_eks\_custom\_node\_pools) | ../.. | n/a | | [vpc](#module\_vpc) | terraform-aws-modules/vpc/aws | ~> 6.0 | ## Resources diff --git a/examples/eks-auto-mode/main.tf b/examples/eks-auto-mode/main.tf index e00b825f63..343e340a42 100644 --- a/examples/eks-auto-mode/main.tf +++ b/examples/eks-auto-mode/main.tf @@ -50,6 +50,27 @@ module "eks" { tags = local.tags } +module "eks_custom_node_pools" { + source = "../.." + + name = "${local.name}-cnp" + kubernetes_version = local.kubernetes_version + endpoint_public_access = true + deletion_protection = true + + enable_cluster_creator_admin_permissions = true + + compute_config = { + enabled = true + node_pools = [] + } + + vpc_id = module.vpc.vpc_id + subnet_ids = module.vpc.private_subnets + + tags = local.tags +} + module "disabled_eks" { source = "../.." diff --git a/main.tf b/main.tf index 8ea8629b8d..423ce6aba5 100644 --- a/main.tf +++ b/main.tf @@ -58,12 +58,12 @@ resource "aws_eks_cluster" "this" { } dynamic "compute_config" { - for_each = var.compute_config != null ? [var.compute_config] : [] + for_each = var.compute_config[*] content { enabled = compute_config.value.enabled - node_pools = compute_config.value.node_pools - node_role_arn = compute_config.value.node_pools != null ? try(aws_iam_role.eks_auto[0].arn, compute_config.value.node_role_arn) : null + node_pools = compute_config.value.enabled ? compute_config.value.node_pools : [] + node_role_arn = compute_config.value.enabled ? (length(compute_config.value.node_pools) > 0 ? try(aws_iam_role.eks_auto[0].arn, compute_config.value.node_role_arn) : null) : null } } @@ -81,7 +81,7 @@ resource "aws_eks_cluster" "this" { content { dynamic "elastic_load_balancing" { - for_each = local.auto_mode_enabled ? [1] : [] + for_each = var.compute_config[*] content { enabled = local.auto_mode_enabled @@ -148,7 +148,7 @@ resource "aws_eks_cluster" "this" { } dynamic "storage_config" { - for_each = local.auto_mode_enabled ? [1] : [] + for_each = var.compute_config[*] content { block_storage { diff --git a/variables.tf b/variables.tf index 9647017980..70590ce98a 100644 --- a/variables.tf +++ b/variables.tf @@ -66,7 +66,7 @@ variable "compute_config" { description = "Configuration block for the cluster compute configuration" type = object({ enabled = optional(bool, false) - node_pools = optional(list(string)) + node_pools = optional(list(string), []) node_role_arn = optional(string) }) default = null