Search⌘ K
AI Features

Configure Resource Using a dynamic Block

Explore how to configure Terraform resources using dynamic blocks to automate and scale nested block generation. Learn the syntax, use of iterators, and how dynamic blocks improve infrastructure as code by balancing scalability and readability.

In the previous lesson, we saw an example of a virtual network with a single subnet defined as a nested block.

Go (1.6.2)
subnet {
name = "subnet1"
address_prefix = cidrsubnet(var.address_space[0],8,1)
}

The dynamic block

A virtual network will typically involve more than one subnet. We could define a separate nested block for each subnet, but that’s not a scalable or dynamic approach. It makes more sense to dynamically generate the nested blocks based on t ...

...