From 9be0e53357a8c95c3a33744d4cbe65b1586daee5 Mon Sep 17 00:00:00 2001 From: Kilian Date: Fri, 5 Apr 2024 14:22:18 +0200 Subject: [PATCH] enha: added option for multiple node groups --- main.tf | 33 +++++++++++++++++++++++---------- variables.tf | 51 +++++++++++++++++++++------------------------------ 2 files changed, 44 insertions(+), 40 deletions(-) diff --git a/main.tf b/main.tf index 07f58c9..8e652a3 100644 --- a/main.tf +++ b/main.tf @@ -131,22 +131,35 @@ resource "aws_eks_cluster" "main" { } resource "aws_eks_node_group" "main" { + count = length(var.node_groups) cluster_name = aws_eks_cluster.main.name - node_group_name = var.identifier + node_group_name = var.node_groups[count.index]["identifier"] node_role_arn = aws_iam_role.worker.arn - subnet_ids = var.subnets - capacity_type = "ON_DEMAND" - disk_size = var.disk_size - instance_types = var.instance_types + subnet_ids = var.node_groups[count.index]["subnets"] + + launch_template { + id = var.node_groups[count.index]["launch_template"]["id"] + version = var.node_groups[count.index]["launch_template"]["version"] + } scaling_config { - desired_size = var.desired_size - max_size = var.max_size - min_size = var.min_size + desired_size = var.node_groups[count.index]["desired_size"] + min_size = var.node_groups[count.index]["min_size"] + max_size = var.node_groups[count.index]["max_size"] } - update_config { - max_unavailable = 1 + # ignore changes made by autoscaling to desired_size + lifecycle { + ignore_changes = [scaling_config[0].desired_size] + } + + dynamic "taint" { + for_each = var.node_groups[count.index]["taints"] + content { + key = taint.value["key"] + value = taint.value["value"] + effect = taint.value["effect"] + } } tags = var.tags diff --git a/variables.tf b/variables.tf index 58ca13e..1005de6 100644 --- a/variables.tf +++ b/variables.tf @@ -14,7 +14,7 @@ variable "kubernetes_version" { } variable "subnets" { - description = "A list of IDs of subnets for the subnet group and potentially the RDS proxy." + description = "A list of subnet IDs for the managed master nodes to run." type = list(string) validation { condition = length(var.subnets) > 0 @@ -27,7 +27,7 @@ variable "subnets" { } variable "security_groups" { - description = "A list of IDs of subnets for the subnet group and potentially the RDS proxy." + description = "A list of security group IDs to be applied to the entire cluster." type = list(string) default = [] validation { @@ -36,34 +36,25 @@ variable "security_groups" { } } -variable "disk_size" { - description = "Disk size in GiB of the node group." - type = number - default = 20 -} - -variable "instance_types" { - description = "Types of the instances in the node group." - type = list(string) - default = ["t3.small"] -} - -variable "desired_size" { - description = "Desired amount of nodes in the node group." - type = number - default = 1 -} - -variable "min_size" { - description = "Minimum amount of nodes in the node group." - type = number - default = 1 -} - -variable "max_size" { - description = "Maximum amount of nodes in the node group." - type = number - default = 1 +variable "node_groups" { + description = "A list of objects to define a group of worker nodes inside the cluster." + type = list(object({ + identifier = string + subnets = list(string) + desired_size = optional(number, 1) + min_size = optional(number, 1) + max_size = optional(number, 1) + launch_template = object({ + id = string + version = optional(string, "$Latest") + }) + taints = optional(list(object({ + key = string + value = string + effect = string + })), []) + })) + default = [] } variable "service_accounts" {