From bba7c151c81f83db9a948c853d5b27d39313982d Mon Sep 17 00:00:00 2001 From: huddy Date: Sat, 7 Nov 2020 21:20:22 +0000 Subject: [PATCH] feat: Tags passed into worker groups override tags from `var.tags` for Autoscaling Groups (#1092) NOTES: Tags that are passed into `var.worker_groups_launch_template` or `var.worker_groups` now override tags passed in via `var.tags` for Autoscaling Groups only. This allow ASG Tags to be overwritten, so that `propagate_at_launch` can be tweaked for a particular key. --- README.md | 2 +- local.tf | 9 --------- variables.tf | 2 +- workers.tf | 10 +++++++++- workers_launch_template.tf | 10 +++++++++- 5 files changed, 20 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 44fbcfe..d4ae770 100644 --- a/README.md +++ b/README.md @@ -205,7 +205,7 @@ MIT Licensed. See [LICENSE](https://github.com/terraform-aws-modules/terraform-a | node\_groups\_defaults | Map of values to be applied to all node groups. See `node_groups` module's documentation for more details | `any` | `{}` | no | | permissions\_boundary | If provided, all IAM roles will be created with this permissions boundary attached. | `string` | `null` | no | | subnets | A list of subnets to place the EKS cluster and workers within. | `list(string)` | n/a | yes | -| tags | A map of tags to add to all resources. | `map(string)` | `{}` | no | +| tags | A map of tags to add to all resources. Tags added to launch coniguration or templates override these values for ASG Tags only. | `map(string)` | `{}` | no | | vpc\_id | VPC where the cluster and workers will be deployed. | `string` | n/a | yes | | wait\_for\_cluster\_cmd | Custom local-exec command to execute for determining if the eks cluster is healthy. Cluster endpoint will be available as an environment variable called ENDPOINT | `string` | `"for i in `seq 1 60`; do if `command -v wget > /dev/null`; then wget --no-check-certificate -O - -q $ENDPOINT/healthz >/dev/null && exit 0 || true; else curl -k -s $ENDPOINT/healthz >/dev/null && exit 0 || true;fi; sleep 5; done; echo TIMEOUT && exit 1"` | no | | wait\_for\_cluster\_interpreter | Custom local-exec command line interpreter for the command to determining if the eks cluster is healthy. | `list(string)` |
[
"/bin/sh",
"-c"
]
| no | diff --git a/local.tf b/local.tf index cd6ac7e..7e649a4 100644 --- a/local.tf +++ b/local.tf @@ -1,13 +1,4 @@ locals { - asg_tags = [ - for item in keys(var.tags) : - map( - "key", item, - "value", element(values(var.tags), index(keys(var.tags), item)), - "propagate_at_launch", "true" - ) - if item != "Name" - ] cluster_security_group_id = var.cluster_create_security_group ? join("", aws_security_group.cluster.*.id) : var.cluster_security_group_id cluster_primary_security_group_id = var.cluster_version >= 1.14 ? element(concat(aws_eks_cluster.this[*].vpc_config[0].cluster_security_group_id, list("")), 0) : null diff --git a/variables.tf b/variables.tf index 4c74731..965e127 100644 --- a/variables.tf +++ b/variables.tf @@ -85,7 +85,7 @@ variable "subnets" { } variable "tags" { - description = "A map of tags to add to all resources." + description = "A map of tags to add to all resources. Tags added to launch coniguration or templates override these values for ASG Tags only." type = map(string) default = {} } diff --git a/workers.tf b/workers.tf index 5c05981..b18ba70 100644 --- a/workers.tf +++ b/workers.tf @@ -126,7 +126,15 @@ resource "aws_autoscaling_group" "workers" { "propagate_at_launch" = true }, ], - local.asg_tags, + [ + for tag_key, tag_value in var.tags : + map( + "key", tag_key, + "value", tag_value, + "propagate_at_launch", "true" + ) + if tag_key != "Name" && ! contains([for tag in lookup(var.worker_groups[count.index], "tags", local.workers_group_defaults["tags"]) : tag["key"]], tag_key) + ], lookup( var.worker_groups[count.index], "tags", diff --git a/workers_launch_template.tf b/workers_launch_template.tf index 8930124..0013fe3 100644 --- a/workers_launch_template.tf +++ b/workers_launch_template.tf @@ -202,7 +202,15 @@ resource "aws_autoscaling_group" "workers_launch_template" { "propagate_at_launch" = true }, ], - local.asg_tags, + [ + for tag_key, tag_value in var.tags : + map( + "key", tag_key, + "value", tag_value, + "propagate_at_launch", "true" + ) + if tag_key != "Name" && ! contains([for tag in lookup(var.worker_groups_launch_template[count.index], "tags", local.workers_group_defaults["tags"]) : tag["key"]], tag_key) + ], lookup( var.worker_groups_launch_template[count.index], "tags",