Skip to content

Commit

Permalink
enha: added option for multiple node groups
Browse files Browse the repository at this point in the history
  • Loading branch information
kfc-manager committed Apr 5, 2024
1 parent 6fb427a commit 9be0e53
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 40 deletions.
33 changes: 23 additions & 10 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
51 changes: 21 additions & 30 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand All @@ -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" {
Expand Down

0 comments on commit 9be0e53

Please sign in to comment.