concept

Dynamic nested blocks

Dynamic blocks create repeated child configuration inside a supported parent. The iterator provides the current element; the provider schema controls valid children. This example uses a fictional provider and is not executable.

Formal Syntax & Structure

terraform syntaxterraform
Dynamic nested blocks

Working Example

Example Snippetterraform
locals {  rules = [    { name = "staff", port = 443 },    { name = "health", port = 8443 }  ]}resource "training_policy" "office" {  name = "office"  dynamic "rule" {    for_each = local.rules    iterator = entry    content {      name = entry.value.name      port = entry.value.port    }  }}
Terraform Reference