Closed DanielMSchmidt closed 11 months ago
While this might not be that much better than Fn.lookup
– we might think about exposing the PropertyAccess
expression. The good thing about that way, would be that it supports a path, which might be more readable for nested access:
Fn.Lookup(Fn.Lookup(Fn.Lookup(mapRef, "c"), "b"), "a")
// vs.
Todo.propertyAccess(mapRef, ["a", "b", "c"])
(Sidenote: I left out the defaultValue
param for lookup for simplicity, as that one is actually still optional but discouraged since TF 0.7; docs)
We might even expose this via TF functions 🤔
Maybe Fn.property(mapRef, ["a", "b", "c"])
(like lodash) or some better wording. Another idea would be to do the following:
Fn.lookup(ref, property, defaultValue) // => lookup() TF call
Fn.lookup(ref, property) // => ref[property] TF expression
Fn.lookupNested(ref, [propertyA, propertyB]) // => ref[propertyA][propertyB] TF expression
What do you think? 🤔
I think that's a good idea
I'm going to lock this issue because it has been closed for 30 days. This helps our maintainers find and focus on the active issues. If you've found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.
Community Note
cdktf & Language Versions
Affected Resource(s)
Summary
Converting this example leads to an invalid access to the project key in the map, where a
Fn.lookup
call would have been necessary