Example of for_each with list -> set using toset

This commit is contained in:
Paul Leddy 2020-05-19 16:03:21 -07:00
parent e1dcae17b7
commit 3d17c87698
1 changed files with 9 additions and 1 deletions

View File

@ -346,6 +346,8 @@ that cannot be determined before apply, and a `-target` may be needed. `for_each
cannot be the result (or rely on the result of) of impure functions, including `uuid`, `bcrypt`, cannot be the result (or rely on the result of) of impure functions, including `uuid`, `bcrypt`,
or `timestamp`, as their evaluation is deferred resource during evaluation. or `timestamp`, as their evaluation is deferred resource during evaluation.
Map:
```hcl ```hcl
resource "azurerm_resource_group" "rg" { resource "azurerm_resource_group" "rg" {
for_each = { for_each = {
@ -356,7 +358,14 @@ resource "azurerm_resource_group" "rg" {
location = each.value location = each.value
} }
``` ```
Set of strings:
```hcl
resource "aws_iam_user" "the-accounts" {
for_each = toset( ["Todd", "James", "Alice", "Dottie"] )
name = each.key
}
```
#### The `each` Object #### The `each` Object
In resource blocks where `for_each` is set, an additional `each` object is In resource blocks where `for_each` is set, an additional `each` object is
@ -680,4 +689,3 @@ The set of configurable operations is chosen by each resource type. Most
resource types do not support the `timeouts` block at all. Consult the resource types do not support the `timeouts` block at all. Consult the
documentation for each resource type to see which operations it offers documentation for each resource type to see which operations it offers
for configuration, if any. for configuration, if any.