Update docs to generalize/use fake example vs one that could be misleading

This commit is contained in:
Pam Selle 2020-01-24 12:44:07 -05:00
parent b1313eaf7d
commit 885ff69c50
1 changed files with 12 additions and 13 deletions

View File

@ -664,29 +664,28 @@ form. This covers many uses, but some resource types include repeatable _nested
blocks_ in their arguments, which do not accept expressions: blocks_ in their arguments, which do not accept expressions:
```hcl ```hcl
resource "aws_security_group" "example" { resource "sample_resource" "example" {
name = "example" # can use expressions here name = "example" # can use expressions here
ingress { repeatable_block {
# but the "ingress" block is always a literal block # but the "repeatable_block" block is always a literal block
} }
} }
``` ```
You can dynamically construct repeatable nested blocks like `ingress` using a You can dynamically construct repeatable nested blocks like `repeatable_block` using a
special `dynamic` block type, which is supported inside `resource`, `data`, special `dynamic` block type, which is supported inside `resource`, `data`,
`provider`, and `provisioner` blocks: `provider`, and `provisioner` blocks:
```hcl ```hcl
resource "aws_security_group" "example" { resource "sample_resource" "example" {
name = "example" # can use expressions here name = "example" # can use expressions here
dynamic "ingress" { dynamic "repeatable_block" {
for_each = var.service_ports for_each = var.things
content { content {
from_port = ingress.value val1 = repeatable_block.value
to_port = ingress.value val2 = repeatable_block.value
protocol = "tcp"
} }
} }
} }
@ -696,12 +695,12 @@ A `dynamic` block acts much like a `for` expression, but produces nested blocks
instead of a complex typed value. It iterates over a given complex value, and instead of a complex typed value. It iterates over a given complex value, and
generates a nested block for each element of that complex value. generates a nested block for each element of that complex value.
- The label of the dynamic block (`"ingress"` in the example above) specifies - The label of the dynamic block (`"repeatable_block"` in the example above) specifies
what kind of nested block to generate. what kind of nested block to generate.
- The `for_each` argument provides the complex value to iterate over. - The `for_each` argument provides the complex value to iterate over.
- The `iterator` argument (optional) sets the name of a temporary variable - The `iterator` argument (optional) sets the name of a temporary variable
that represents the current element of the complex value. If omitted, the name that represents the current element of the complex value. If omitted, the name
of the variable defaults to the label of the `dynamic` block (`"ingress"` in of the variable defaults to the label of the `dynamic` block (`"repeatable_block"` in
the example above). the example above).
- The `labels` argument (optional) is a list of strings that specifies the block - The `labels` argument (optional) is a list of strings that specifies the block
labels, in order, to use for each generated block. You can use the temporary labels, in order, to use for each generated block. You can use the temporary
@ -713,7 +712,7 @@ Since the `for_each` argument accepts any collection or structural value,
you can use a `for` expression or splat expression to transform an existing you can use a `for` expression or splat expression to transform an existing
collection. collection.
The iterator object (`ingress` in the example above) has two attributes: The iterator object (`repeatable_block` in the example above) has two attributes:
* `key` is the map key or list element index for the current element. If the * `key` is the map key or list element index for the current element. If the
`for_each` expression produces a _set_ value then `key` is identical to `for_each` expression produces a _set_ value then `key` is identical to