Difference between revisions of "Terraform: dynamic blocks"
Jump to navigation
Jump to search
m (Welcome moved page Terraform: dynamic to Terraform: dynamic blocks) |
|||
(11 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
https://www.terraform.io/language/expressions/dynamic-blocks | https://www.terraform.io/language/expressions/dynamic-blocks | ||
+ | A dynamic block acts much like a <code>[[for]]</code> expression. | ||
+ | |||
+ | <code>[[dynamic]] { }</code> | ||
+ | |||
+ | == Example == | ||
+ | dynamic "parameter" { | ||
+ | [[for_each]] = var.parameters | ||
+ | content { | ||
+ | name = parameter.value.name | ||
+ | value = parameter.value.value | ||
+ | apply_method = [[lookup]](parameter.value, "apply_method", null) | ||
+ | } | ||
+ | } | ||
+ | |||
+ | |||
+ | <pre> | ||
+ | locals { | ||
+ | dynamic = "key_b" | ||
+ | my_map_json = jsonencode({ | ||
+ | key_a = "something" | ||
+ | (local.dynamic) = "else" | ||
+ | }) | ||
+ | # ... | ||
+ | } | ||
+ | </pre> | ||
+ | Ref: https://github.com/hashicorp/terraform/issues/27037#issuecomment-734356738 | ||
+ | |||
+ | == Related == | ||
+ | * [[Terraform blocks]] | ||
== See also == | == See also == | ||
− | * {{Terraform}} | + | * {{Terraform blocks}} |
+ | * {{for_each}} | ||
+ | |||
+ | [[Category:Terraform]] |
Latest revision as of 16:30, 31 October 2024
https://www.terraform.io/language/expressions/dynamic-blocks
A dynamic block acts much like a for
expression.
dynamic { }
Example[edit]
dynamic "parameter" { for_each = var.parameters content { name = parameter.value.name value = parameter.value.value apply_method = lookup(parameter.value, "apply_method", null) } }
locals { dynamic = "key_b" my_map_json = jsonencode({ key_a = "something" (local.dynamic) = "else" }) # ... }
Ref: https://github.com/hashicorp/terraform/issues/27037#issuecomment-734356738
Related[edit]
See also[edit]
Advertising: