More in expressions, removed extra resource thing

This commit is contained in:
Pam Selle 2019-10-01 13:26:48 -04:00
parent 67e314dcbe
commit 2a50bc6b5a
2 changed files with 26 additions and 5 deletions

View File

@ -295,11 +295,11 @@ for use in references, as follows:
To obtain a map of values of a particular argument for _labelled_ nested To obtain a map of values of a particular argument for _labelled_ nested
block types, use a [`for` expression](#for-expressions): block types, use a [`for` expression](#for-expressions):
`[for k, device in aws_instance.example.device : k => device.size]`. `{for k, device in aws_instance.example.device : k => device.size}`.
When a particular resource has the special When a resource has the
[`count`](https://www.terraform.io/docs/configuration/resources.html#count-multiple-resource-instances-by-count) [`count`](https://www.terraform.io/docs/configuration/resources.html#count-multiple-resource-instances-by-count)
argument set, the resource itself becomes a list of instance objects rather than argument set, the resource itself becomes a _list_ of instance objects rather than
a single object. In that case, access the attributes of the instances using a single object. In that case, access the attributes of the instances using
either [splat expressions](#splat-expressions) or index syntax: either [splat expressions](#splat-expressions) or index syntax:
@ -307,6 +307,29 @@ either [splat expressions](#splat-expressions) or index syntax:
instances. instances.
* `aws_instance.example[0].id` returns just the id of the first instance. * `aws_instance.example[0].id` returns just the id of the first instance.
When a resource has the
[`for_each`](/docs/configuration/resources.html#for_each-multiple-resource-instances-defined-by-a-map-or-set-of-strings)
argument set, the resource itself becomes a _map_ of instance objects rather than
a single object, and attributes of instances must be specified by key, or can
be accessed using a [`for` expression](#for-expressions).
* `aws_instance.example["a"].id` returns the id of the "a"-keyed resource.
* `[for value in aws_instance.example: value.id]` returns a list of all of the ids
of each of the instances.
### Local Named Values
Within the bodies of certain expressions, or in some other specific contexts,
there are other named values available beyond the global values listed above.
(For example, the body of a resource block where `count` is set can use a
special `count.index` value.) These local names are described in the
documentation for the specific contexts where they appear.
-> **Note:** Local named values are often referred to as _variables_ or
_temporary variables_ in their documentation. These are not [input
variables](./variables.html); they are just arbitrary names
that temporarily represent a value.
### Values Not Yet Known ### Values Not Yet Known
When Terraform is planning a set of changes that will apply your configuration, When Terraform is planning a set of changes that will apply your configuration,

View File

@ -370,8 +370,6 @@ identified by a map key (or set member) from the value provided to `for_each`.
- `<TYPE>.<NAME>` (for example, `azurerm_resource_group.rg`) refers to the resource block. - `<TYPE>.<NAME>` (for example, `azurerm_resource_group.rg`) refers to the resource block.
- `<TYPE>.<NAME>[<KEY>]` (for example, `azurerm_resource_group.rg["a_group"]`, - `<TYPE>.<NAME>[<KEY>]` (for example, `azurerm_resource_group.rg["a_group"]`,
`azurerm_resource_group.rg["another_group"]`, etc.) refers to individual instances. `azurerm_resource_group.rg["another_group"]`, etc.) refers to individual instances.
- `{ for key, value in <TYPE>.<NAME> : key => value.public_ip }`, an expression referring to instances
in a resource managed with `for_each`
This is different from resources without `count` or `for_each`, which can be This is different from resources without `count` or `for_each`, which can be
referenced without an index or key. referenced without an index or key.