Last active
September 10, 2021 01:06
-
-
Save josharrington/c0022105e65db142d5d68dbfce039047 to your computer and use it in GitHub Desktop.
for_each over complex map
This file contains hidden or 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
locals { | |
sqs_queues = { | |
usertrack = { | |
topics = ["foo", "bar", "baz"] | |
} | |
another = { | |
topics = ["asdf", "1234"] | |
} | |
} | |
sns_topics = merge([ | |
for k,v in local.sqs_queues : { | |
for topic in v.topics : "${k}_${topic}" => {queue = k, topic = topic} | |
} | |
]...) | |
} | |
output test { | |
value = local.sns_topics | |
} | |
# resource aws_sqs_queue queue { | |
# for_each = var.sqs_queues | |
# ... | |
# } | |
# resource aws_sns_topic topic { | |
# for_each = var.sns_topics | |
# ... | |
# } | |
# Outputs: | |
# test = { | |
# "another_1234" = { | |
# "queue" = "another" | |
# "topic" = "1234" | |
# } | |
# "another_asdf" = { | |
# "queue" = "another" | |
# "topic" = "asdf" | |
# } | |
# "usertrack_bar" = { | |
# "queue" = "usertrack" | |
# "topic" = "bar" | |
# } | |
# "usertrack_baz" = { | |
# "queue" = "usertrack" | |
# "topic" = "baz" | |
# } | |
# "usertrack_foo" = { | |
# "queue" = "usertrack" | |
# "topic" = "foo" | |
# } | |
# } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment