diff --git a/CHANGELOG.md b/CHANGELOG.md index 20a2a4a8db..490e062d62 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ project adheres to [Semantic Versioning](http://semver.org/). ##### Added - Ability to configure force_delete for the worker group ASG (by @stefansedich) +- Ability to configure worker group ASG tags (by @stefansedich) - Added EBS optimized mapping for the g3s.xlarge instance type (by @stefansedich) - `enabled_metrics` input (by @zanitete) diff --git a/README.md b/README.md index 0683a50b75..c08aa7ad40 100644 --- a/README.md +++ b/README.md @@ -137,6 +137,8 @@ MIT Licensed. See [LICENSE](https://github.com/terraform-aws-modules/terraform-a | worker\_create\_security\_group | Whether to create a security group for the workers or attach the workers to `worker_security_group_id`. | string | `"true"` | no | | worker\_group\_count | The number of maps contained within the worker_groups list. | string | `"1"` | no | | worker\_group\_launch\_template\_count | The number of maps contained within the worker_groups_launch_template list. | string | `"0"` | no | +| worker\_group\_launch\_template\_tags | A map defining extra tags to be applied to the worker group template ASG. | map | `` | no | +| worker\_group\_tags | A map defining extra tags to be applied to the worker group ASG. | map | `` | no | | worker\_groups | A list of maps defining worker group configurations to be defined using AWS Launch Configurations. See workers_group_defaults for valid keys. | list | `[ { "name": "default" } ]` | no | | worker\_groups\_launch\_template | A list of maps defining worker group configurations to be defined using AWS Launch Templates. See workers_group_defaults for valid keys. | list | `[ { "name": "default" } ]` | no | | worker\_security\_group\_id | If provided, all workers will be attached to this security group. If not given, a security group will be created with necessary ingres/egress to work with the EKS cluster. | string | `""` | no | diff --git a/examples/eks_test_fixture/main.tf b/examples/eks_test_fixture/main.tf index 8c830a0b39..186ac1cb6c 100644 --- a/examples/eks_test_fixture/main.tf +++ b/examples/eks_test_fixture/main.tf @@ -39,6 +39,26 @@ locals { # }, # ] + + # the commented out worker group tags below shows an example of how to define + # custom tags for the worker groups ASG + # worker_group_tags = { + # worker_group_a = [ + # { + # key = "k8s.io/cluster-autoscaler/node-template/taint/nvidia.com/gpu" + # value = "gpu:NoSchedule" + # propagate_at_launch = true + # }, + # ], + # worker_group_b = [ + # { + # key = "k8s.io/cluster-autoscaler/node-template/taint/nvidia.com/gpu" + # value = "gpu:NoSchedule" + # propagate_at_launch = true + # }, + # ], + # } + worker_groups = [ { # This will launch an autoscaling group with only On-Demand instances diff --git a/variables.tf b/variables.tf index 1937585d9c..e1208f0e9b 100644 --- a/variables.tf +++ b/variables.tf @@ -101,6 +101,15 @@ variable "workers_group_defaults" { default = {} } +variable "worker_group_tags" { + description = "A map defining extra tags to be applied to the worker group ASG." + type = "map" + + default = { + default = [] + } +} + variable "worker_groups_launch_template" { description = "A list of maps defining worker group configurations to be defined using AWS Launch Templates. See workers_group_defaults for valid keys." type = "list" @@ -124,6 +133,15 @@ variable "workers_group_launch_template_defaults" { default = {} } +variable "worker_group_launch_template_tags" { + description = "A map defining extra tags to be applied to the worker group template ASG." + type = "map" + + default = { + default = [] + } +} + variable "worker_security_group_id" { description = "If provided, all workers will be attached to this security group. If not given, a security group will be created with necessary ingres/egress to work with the EKS cluster." default = "" diff --git a/workers.tf b/workers.tf index 1835eb27d3..af3d5033b0 100644 --- a/workers.tf +++ b/workers.tf @@ -20,7 +20,8 @@ resource "aws_autoscaling_group" "workers" { map("key", "kubernetes.io/cluster/${aws_eks_cluster.this.name}", "value", "owned", "propagate_at_launch", true), map("key", "k8s.io/cluster-autoscaler/${lookup(var.worker_groups[count.index], "autoscaling_enabled", local.workers_group_defaults["autoscaling_enabled"]) == 1 ? "enabled" : "disabled" }", "value", "true", "propagate_at_launch", false) ), - local.asg_tags) + local.asg_tags, + var.worker_group_tags[contains(keys(var.worker_group_tags), "${lookup(var.worker_groups[count.index], "name", count.index)}") ? "${lookup(var.worker_groups[count.index], "name", count.index)}" : "default"]) }"] lifecycle { diff --git a/workers_launch_template.tf b/workers_launch_template.tf index 17d0fb3341..8bcfee2e84 100644 --- a/workers_launch_template.tf +++ b/workers_launch_template.tf @@ -46,7 +46,8 @@ resource "aws_autoscaling_group" "workers_launch_template" { map("key", "kubernetes.io/cluster/${aws_eks_cluster.this.name}", "value", "owned", "propagate_at_launch", true), map("key", "k8s.io/cluster-autoscaler/${lookup(var.worker_groups_launch_template[count.index], "autoscaling_enabled", local.workers_group_launch_template_defaults["autoscaling_enabled"]) == 1 ? "enabled" : "disabled" }", "value", "true", "propagate_at_launch", false) ), - local.asg_tags) + local.asg_tags, + var.worker_group_launch_template_tags[contains(keys(var.worker_group_launch_template_tags), "${lookup(var.worker_groups_launch_template[count.index], "name", count.index)}") ? "${lookup(var.worker_groups_launch_template[count.index], "name", count.index)}" : "default"]) }"] lifecycle {