Implement block-level iterators
See original GitHub issueCommunity 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
To support dynamic list iterations on the block / resource level we will introduce a new API, called Iterator.
In this issue we are building the block-level Iterator API. To create dynamic blocks one can use iterator.dynamic([…]) and the block will be repeated for each item in the list.
import { TerraformStack, Iterator } from "cdktf";
import { S3Bucket, DataAwsSubnets, DataAwsAllowedOrigins } from "./.gen/providers/aws-ficticious";
import { Construct } from "constructs";
export class MyStack extends TerraformStack {
constructor(scope: Construct, id: string) {
super(scope, id);
// Fictitious data source that returns [{method, origin}]
const allowedOrigins = new DataAwsAllowedOrigins(
this,
"possibleOrigins",
{}
);
const allowedOriginsIterator = Iterator.fromList(allowedOrigins.origins);
new S3Bucket(this, "my-bucket", {
corsRule: allowedOriginsIterator.dynamic(
{
allowedMethods: [allowedOriginsIterator.getStringProperty("method")],
allowedOrigins: [allowedOriginsIterator.getStringProperty("origin")],
maxAgeSeconds: 42,
},
),
});
}
}
References
Issue Analytics
- State:
- Created a year ago
- Reactions:2
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Implementing iterator blocks in C++ (part 1)
Recently I had to port some C# code to C++. The C# code was making a limited use of the .NET framework, so,...
Read more >Iterators & iterables | Ben Ilegbodu
An iterable is an object that intends to make its sequential elements publicly accessible through iteration interfaces. This object does so by ...
Read more >Is there a way I can combine two separate iterator blocks to one?
In short, no, you cannot have nested yield iterator within the same method. yield is compiled at the method level.
Read more >BlockGraph (Soot API)
public abstract class BlockGraph; extends Object; implements DirectedGraph<Block>. Represents the control flow graph of a Body at the basic block level.
Read more >Terraform HCL Intro 5: Loops with Dynamic Block - BoltOps Blog
For Each Difference: Resource vs Dynamic Block Level. In the previous post, we covered how to use the for_each attribute at the resource ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi @RichiCoder1, yeah, I thought about that, too. However, as we’re constrained by JSII (which translates our TypeScript bindings to the other languages we support), we can’t directly use callbacks, but rather need to pass what would for example be the equivalent of an anonymous inner class in Java. So it would need to look like this:
I’m unsure whether this would still simplify things compared to
.dynamic({ ... })
or even.forEach({ ... })
.@ansgarm that’s fair, JSII strikes again.
dynamic
seems fine then, considering constraints