Skip to content

Commit

Permalink
website: Additional information about "dynamic" blocks
Browse files Browse the repository at this point in the history
Based on some common questions and feedback since the v0.12.0 release,
here we add some small additional content to the documentation for
"dynamic" blocks, covering how to access the keys of the collection being
iterated over and how to fold multiple collections into a single one to
achieve the effect of a nested iteration.
  • Loading branch information
apparentlymart committed Jun 5, 2019
1 parent b84562d commit 127cbee
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions website/docs/configuration/expressions.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -673,12 +673,23 @@ Since the `for_each` argument accepts any collection or structural value,
you can use a `for` expression or splat expression to transform an existing
collection.

The iterator object (`ingress` in the example above) has two attributes:

* `key` is the map key or list element index for the current element. If the
`for_each` exression produces a _set_ value then `key` is identical to
`value` and should not be used.
* `value` is the value of the current element.

A `dynamic` block can only generate arguments that belong to the resource type,
data source, provider or provisioner being configured. It is _not_ possible
to generate meta-argument blocks such as `lifecycle` and `provisioner`
blocks, since Terraform must process these before it is safe to evaluate
expressions.

If you need to iterate over combinations of values from multiple collections,
use [`setproduct`](./functions/setproduct.html) to create a single collection
containing all of the combinations.

### Best Practices for `dynamic` Blocks

Overuse of `dynamic` blocks can make configuration hard to read and maintain, so
Expand Down

0 comments on commit 127cbee

Please sign in to comment.