Terraform Dynamic Block

Why are dynamic blocks ?

  • Dynamically constructs repeatable nested configuration blocks inside Terraform resources.

  • Supported within the block types:

    • resource

    • data

    • provider

    • provisioner

  • Use to make your code cleaner

How to configure Dynamic Blocks

  • Dynamic blocks expect a complex variable type to iterate over.

  • It acts like a for-loop and outputs a nested block for each element in your variable.

CAUTION

  • Be careful not to overuse dynamic blocks in your main code, as they can be hard to read and maintain

  • Only use dynamic blocks when you need to hide details in order to build a cleaner user interface when writing reusable modules.

Last updated