From fcfbfb3eff4b73670fe34693dfa0a7178cc83dc9 Mon Sep 17 00:00:00 2001 From: Radek Simko Date: Wed, 28 Feb 2024 08:58:17 +0000 Subject: [PATCH] website: ensure for_each examples take maps (#34675) --- website/docs/cli/state/resource-addressing.mdx | 4 ++-- website/docs/language/functions/csvdecode.mdx | 2 +- website/docs/language/functions/flatten.mdx | 4 ++-- website/docs/language/functions/setproduct.mdx | 4 ++-- website/docs/language/meta-arguments/for_each.mdx | 8 ++++---- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/website/docs/cli/state/resource-addressing.mdx b/website/docs/cli/state/resource-addressing.mdx index 072e9c205c..788b1a4976 100644 --- a/website/docs/cli/state/resource-addressing.mdx +++ b/website/docs/cli/state/resource-addressing.mdx @@ -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", - } + }) } ``` diff --git a/website/docs/language/functions/csvdecode.mdx b/website/docs/language/functions/csvdecode.mdx index 2af18afd41..c6262c4558 100644 --- a/website/docs/language/functions/csvdecode.mdx +++ b/website/docs/language/functions/csvdecode.mdx @@ -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 diff --git a/website/docs/language/functions/flatten.mdx b/website/docs/language/functions/flatten.mdx index b3330f9027..461f44f343 100644 --- a/website/docs/language/functions/flatten.mdx +++ b/website/docs/language/functions/flatten.mdx @@ -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 diff --git a/website/docs/language/functions/setproduct.mdx b/website/docs/language/functions/setproduct.mdx index 077f4cbaa7..39298bbcb2 100644 --- a/website/docs/language/functions/setproduct.mdx +++ b/website/docs/language/functions/setproduct.mdx @@ -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 diff --git a/website/docs/language/meta-arguments/for_each.mdx b/website/docs/language/meta-arguments/for_each.mdx index 423167cdd0..7001fd08fd 100644 --- a/website/docs/language/meta-arguments/for_each.mdx +++ b/website/docs/language/meta-arguments/for_each.mdx @@ -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 } ```