website: ensure for_each examples take maps (#34675)

pull/34744/head
Radek Simko 2 years ago committed by GitHub
parent cec4b7b74c
commit fcfbfb3eff
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -118,12 +118,12 @@ Given a Terraform config that includes:
```hcl
resource "aws_instance" "web" {
# ...
for_each = {
for_each = tomap({
"terraform": "value1",
"resource": "value2",
"indexing": "value3",
"example": "value4",
}
})
}
```

@ -63,7 +63,7 @@ locals {
}
resource "aws_instance" "example" {
for_each = { for inst in local.instances : inst.local_id => inst }
for_each = tomap({ for inst in local.instances : inst.local_id => inst })
instance_type = each.value.instance_type
ami = each.value.ami

@ -118,9 +118,9 @@ resource "aws_subnet" "example" {
# local.network_subnets is a list, so we must now project it into a map
# where each key is unique. We'll combine the network and subnet keys to
# produce a single unique key per instance.
for_each = {
for_each = tomap({
for subnet in local.network_subnets : "${subnet.network_key}.${subnet.subnet_key}" => subnet
}
})
vpc_id = each.value.network_id
availability_zone = each.value.subnet_key

@ -190,9 +190,9 @@ resource "aws_subnet" "example" {
# local.network_subnets is a list, so project it into a map
# where each key is unique. Combine the network and subnet keys to
# produce a single unique key per instance.
for_each = {
for_each = tomap({
for subnet in local.network_subnets : "${subnet.network_key}.${subnet.subnet_key}" => subnet
}
})
vpc_id = each.value.network_id
availability_zone = each.value.subnet_key

@ -42,10 +42,10 @@ Map:
```hcl
resource "azurerm_resource_group" "rg" {
for_each = {
a_group = "eastus"
for_each = tomap({
a_group = "eastus"
another_group = "westus2"
}
})
name = each.key
location = each.value
}
@ -55,7 +55,7 @@ Set of strings:
```hcl
resource "aws_iam_user" "the-accounts" {
for_each = toset( ["Todd", "James", "Alice", "Dottie"] )
for_each = toset(["Todd", "James", "Alice", "Dottie"])
name = each.key
}
```

Loading…
Cancel
Save