-
Notifications
You must be signed in to change notification settings - Fork 9.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
allow filtering elements with plain non-transforming for_each #35347
Comments
Thanks for this idea, @ryenus. I think one important implication of your proposed shorthand is that it replaces with explicit declaration of local symbols That isn't necessarily disqualifying, but it does violate the current separation of concerns in how Terraform is built: A variation of this that would not raise these concerns would be to retain the overall for_each = {
for key, value in var.map_of_objects
if value.enabled == true
} This retains the explicit declaration of (I remember that the colon ended up being part of the |
Thanks for this feature request! If you are viewing this issue and would like to indicate your interest, please use the 👍 reaction on the issue description to upvote this issue. We also welcome additional use case descriptions. Thanks again! |
@apparentlymart & @crw, thanks a lot for looking into this. I don't have much insight into the HCL internals yet, but regarding the visibility and/or scope of |
Hi @ryenus, The main tricky thing here is that Using a fixed name in the design of resource and module For anything that's more general we need to provide a way for the local symbol to vary based on context so that the author can select a name that isn't already being used for something else. That's why, for example, My proposed modification was therefore intending to still provide the necessary way to choose the local symbol names, while removing the redundant transformation clause is the case where only filtering is desired and no transformation is needed. |
Is it possible to treat the proposed one as a syntactic sugar, then leverage something like a preprocessor to implicitly convert it to the one with an explicit |
Adding a second pair of eyes here, the original proposal is difficult to read. You are still transforming the value -- you intended to write an expression which takes a map, transform it by filtering keys into a new possibly smaller map, and assign the resulting value to If I were to see the expression Aside from the fact that it may not be possible to parse correctly (haven't given that any thought, but the scope issues were mentioned above), wrapping the expression in |
Terraform Version
Use Cases
filtering a map while iterating with
for_each
Attempted Solutions
Proposal
Since we're only filtering the elements in the input variable "map_of_objects", without performing any transformation. It would be great if we can omit the
for
expression and hoist the filtering expressionReferences
No response
The text was updated successfully, but these errors were encountered: