Open seanturner026 opened 1 year ago
Thank you for your continued interest in this issue.
Terraform version 1.8 launches with support of provider-defined functions. It is now possible to implement your own functions! We would love to see this implemented as a provider-defined function.
Please see the provider-defined functions documentation to learn how to implement functions in your providers. If you are new to provider development, learn how to create a new provider with the Terraform Plugin Framework. If you have any questions, please visit the Terraform Plugin Development category in our official forum.
We hope this feature unblocks future function development and provides more flexibility for the Terraform community. Thank you for your continued support of Terraform!
Terraform Version
Use Cases
Problem to be solved
It is not possible to
for_each
over alist(map)
unless a map comprehension is written which is slower and more tedious to write thanfor_each = local.map_object
.Overview
for_each
requires a map object as it unpacks to at leasteach.key
and optionally includeseach.value
Generally this is done with the following:
for_each
often loops over a longmap
object somewhere inlocals{}
. These objectkeys
can become harder to read at a glance with the rest of the object as the map object gets longer.I believe that it is easier and quicker to read the equivalent
list(map)
as the indentation is more consistent. Further, most modern editors will also render the value of thename
attribute as a different color which makes it stand out more compared to theupdate_*
map keys in the previous example, which are the same color as the other map keys. While not exactly the same idea, this makes me think of Mat Ryer's argument of line of sight (Medium.com -- Code: Align the happy path to the left edgeAttempted Solutions
Considering the above example where
local.eventbridge_list_map
is alist(map)
, the only way to use that object infor_each
is with a map compression.However, using the
list(map)
here is more tedious to write and harder to read than usinglocal.eventbridge_map
despite having the same outcomeProposal
Create a new function
keylistmap()
which has the following interface:keylistmap(key, listmap)
map
in alist(map)
.Invoking
keylistmap
with thelocal.eventbridge_list_map
object would have the following behavior:This would have the benefit of turning the map comprehension example...
Into something more native:
This aims to maximize readability in the iterable through utilizing
list(map)s
as well as in thefor_each
statement by via an ergonomic alternative to a map comprehension.References
No response