Skip to content

Commit

Permalink
Worker group tags (#252)
Browse files Browse the repository at this point in the history
* Allow per worker group ASG tags to be set

* Format

* Set correct defaults

* Implement hack that will use the first item in the list if a matching item does not exist for the worker group

* Use a map that will map from the worker group name to the tags to get around the issue where list indexing does not work with a list of lists

* Format

* Cleanup

* Fix sample

* README
  • Loading branch information
stefansedich authored and max-rocket-internet committed Jan 31, 2019
1 parent eac4164 commit 35747d7
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 | `<map>` | no |
| worker\_group\_tags | A map defining extra tags to be applied to the worker group ASG. | map | `<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 |
Expand Down
20 changes: 20 additions & 0 deletions examples/eks_test_fixture/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 = ""
Expand Down
3 changes: 2 additions & 1 deletion workers.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion workers_launch_template.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 35747d7

Please sign in to comment.