Worker group tags (#252)

* 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
This commit is contained in:
Stefan Sedich
2019-01-31 06:38:53 -08:00
committed by Max Williams
parent eac4164c05
commit 35747d707a
6 changed files with 45 additions and 2 deletions

View File

@@ -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)

View File

@@ -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 |

View File

@@ -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

View File

@@ -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 = ""

View File

@@ -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 {

View File

@@ -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 {