terraform-cdk icon indicating copy to clipboard operation
terraform-cdk copied to clipboard

Provider Bindings: Lists should expose iterators

Open DanielMSchmidt opened this issue 3 years ago • 1 comments
trafficstars

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Description

The generated provider schema should have iterator classes with nicely typed accessors on them generated as part of the binding generation. The UX should look like this:

const iterator = myResource.listPropertyOnTheResource.all();

new MyOtherResource(this, "foo", { forEach: iterator, name: iterator.whateverPropertyAnItemOfTheListHas })

References

  • Follow up work for #1797 and #1798

DanielMSchmidt avatar Jun 14 '22 13:06 DanielMSchmidt

When tackling this, we should also thinking about enabling type support for the target attribute when using .dynamic() for dynamic attributes (see e.g. #2013).

It could look like this for example:

const iterator = myResource.listPropertyOnTheResource.all();

new MyOtherResource(this, "foo", {
  complexListAttribute: new MyOtherResourceComplexListAttributeFromIterator({
    name: iterator.iterator.whateverPropertyAnItemOfTheListHas
  })
});

Currently the type MyOtherResourceComplexListAttribute already exists but is just an interface and it probably needs to stay that way. So introducing a new helper like class MyOtherResourceComplexListAttributeFromIterator extends IResolvable {..} could do the trick. But that is just a rough first idea that needs a few more iterations (especially on the naming 😁☝️).

ansgarm avatar Aug 10 '22 08:08 ansgarm

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.

github-actions[bot] avatar Jan 04 '24 01:01 github-actions[bot]