Created
January 14, 2022 11:08
-
-
Save stevenewey/adba6a73ee9555c4b4bf32293965e025 to your computer and use it in GitHub Desktop.
Retrieve per-AZ autoscaling group names from managed node groups when using the AWS EKS terraform module
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
variable "availability_zones" { | |
type = map(string) | |
description = "Availability zones to use, mapped to networks to assign" | |
default = { | |
"us-east-1a" : "172.16.0.0/18", | |
"us-east-1b" : "172.16.64.0/18", | |
} | |
} | |
locals { | |
/* | |
### autoscaling_groups is parsed from an object like this in module.eks.node_groups | |
node_groups = { | |
"group-a" = { | |
"resources" = tolist([ | |
{ | |
"autoscaling_groups" = tolist([ | |
{ | |
"name" = "eks-use2-dev-1-group-a202201111845031276500000023-52bf253a-9cae-fae8-111d-867d7d3bc695" | |
}, | |
]) | |
"remote_access_security_group_id" = "" | |
}, | |
]) | |
} | |
"group-b" = { | |
"resources" = tolist([ | |
{ | |
"autoscaling_groups" = tolist([ | |
{ | |
"name" = "eks-use2-dev-1-group-b2022011118450321830000002b-70bf253a-9cdb-1bf0-4270-32f4d47b4628" | |
}, | |
]) | |
"remote_access_security_group_id" = "" | |
}, | |
]) | |
} | |
} | |
*/ | |
autoscaling_groups = { | |
for az in keys(var.availability_zones) : az => | |
[for asg in flatten( | |
[for item in module.eks.node_groups["group-${substr(az, -1, 1)}"]["resources"] : item["autoscaling_groups"] | |
if lookup(item, "autoscaling_groups", false) != false] | |
) : asg["name"]] | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment