Difference between revisions of "Terraform: for each"
Jump to navigation
Jump to search
(17 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
+ | <code>for_each</code> [https://developer.hashicorp.com/terraform/language/meta-arguments/for_each ref] | ||
− | for_each | + | == Examples == |
+ | === Official examples === | ||
+ | resource "azurerm_resource_group" "rg" { | ||
+ | for_each = { | ||
+ | a_group = "eastus" | ||
+ | another_group = "westus2" | ||
+ | } | ||
+ | name = [[each.]]key | ||
+ | location = each.value | ||
+ | } | ||
− | [[ | + | resource "[[aws_ssm_parameter]]" "secret" { |
+ | [[for_each]] = toset(var.secrets) | ||
+ | name = each.key | ||
+ | description = each.key | ||
+ | type = "SecureString" | ||
+ | value = "1" | ||
+ | |||
+ | lifecycle { | ||
+ | ignore_changes = [value] | ||
+ | } | ||
+ | } | ||
+ | == Errors == | ||
+ | * <code>[[Error: Unexpected resource instance key]]</code> | ||
− | {{tf}} | + | == Related == |
+ | * <code>[[Terraform expression: for|for]]</code> | ||
+ | * <code>[[Terraform meta argument: count|count]]</code> | ||
+ | * [[Terraform best practices]] | ||
+ | * [[meta arguments]] | ||
+ | |||
+ | == See also == | ||
+ | * {{for_each}} | ||
+ | * {{tf functions}} | ||
+ | |||
+ | [[Category:Terraform]] |
Revision as of 18:01, 14 May 2023
for_each
ref
Examples
Official examples
resource "azurerm_resource_group" "rg" { for_each = { a_group = "eastus" another_group = "westus2" } name = each.key location = each.value }
resource "aws_ssm_parameter" "secret" { for_each = toset(var.secrets) name = each.key description = each.key type = "SecureString" value = "1" lifecycle { ignore_changes = [value] } }
Errors
Related
See also
Advertising: