You can limit the application of for_each to a specific block of code in locals by creating a sub-block using curly braces "{}" and wrapping your code inside it.
For example:
locals {
my_instance = {
for_each = var.instances
my_instance_name = each.value.name
my_instance_type = each.value.type
}
# This is outside the sub-block and won't be affected by for_each
my_other_variable = "value"
}
In this example, foreach is only applied to the myinstance block and not to the myothervariable.
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2023-06-16 14:04:49 +0000
Seen: 13 times
Last updated: Jun 16 '23
How can I center a button using CSS if it is not movable?
Why aren't my try-catch blocks catching exceptions in .Net Maui Android?
How can I replace or modify a specific block within a theme layout in Hugo?
What is the method of adding RichLink (Chip Block) into Google Docs by means of Google App Script?
What does it mean when the if block is not being executed?
How can strings be added to a code block by looking for a matching string within it?
How to perform AES encryption in Golang using the "global" cipher?
What is the method for performing column editing in vim?
If the for_each is empty, should any dynamic resources be disregarded?