dynamic block to generate them from a list. ubx supports the same pattern: the dynamic keyword takes a collection and a content sub-block, and generates one instance of the nested block per element in the collection. The current element is available as <block_name>.value inside content, giving you access to each entry’s attributes. The result is a single declaration that generates as many nested blocks as the collection has entries — and adding a new entry is as simple as adding a new object to the list.
What you’ll learn
- How
dynamicgenerates repeated nested blocks from a list - How to access the current element with
<block_name>.value - When to use
dynamicvs separateunitblocks
Why this matters
Without
dynamic, adding a new port to a security group means adding an entire ingress block by hand. With dynamic, you add one object to a list. The security group’s rule configuration becomes data — easy to read, easy to audit, easy to extend.The source code
How it works
dynamic iterates over the for_each collection
The list of objects is
Resolved<T> — known at compile time. ubx iterates over it in the IR pass and generates one nested block per element, substituting ingress.value.port, ingress.value.protocol, etc. for each entry.content defines the shape of each generated block
The
content sub-block is the template. Every attribute inside it is evaluated once per collection element, with <block_name>.value referring to the current element’s fields.What ubx generates
Common mistakes
Run it
What you learned
dynamic generates one nested block per element in a for_each collectionThe current element is accessed as
<block_name>.value inside the content sub-blockThe generated code expands to explicit nested block objects — no runtime loops
Next steps
Multi-environment with extend
Override attributes per environment with extend blocks
for_each over a list
Create multiple top-level resources from a list
Full runnable example: github.com/ubiquex/ubx-examples/12-dynamic-blocks

