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.
This commit is contained in:
huddy
2020-11-07 21:20:22 +00:00
committed by GitHub
parent 3cb8fa3d87
commit bba7c151c8
5 changed files with 20 additions and 13 deletions

View File

@@ -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)` | <pre>[<br> "/bin/sh",<br> "-c"<br>]</pre> | no |

View File

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

View File

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

View File

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

View File

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