Skip to content

Instantly share code, notes, and snippets.

@abdrehma
Forked from arehmandev/Terraform nested for loop
Last active October 30, 2020 16:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abdrehma/b8a258a085203cd987848c656e32d3bc to your computer and use it in GitHub Desktop.
Save abdrehma/b8a258a085203cd987848c656e32d3bc to your computer and use it in GitHub Desktop.
Terraform nested for loop for_each
locals {
nested_loop = { for entry in flatten(values({
for k, v in var.hub_networks :
k => [
for key, val in var.firewalls :
merge(val, v, { "key" : "default-deny-${lower(val.direction)}-${v.network}" })
]
})) : entry.key => entry }
}
hub_networks = {
int = {
project = "int"
network = "int-network"
}
pre = {
project = "pre"
network = "pre-network"
}
}
firewalls = {
deny_egress = {
direction = "EGRESS"
priority = 65535
}
deny_ingress = {
direction = "INGRESS"
priority = 65534
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment