Below is an example of a loop. We use the content
block of terraform, documented here: https://www.terraform.io/docs/language/expressions/dynamic-blocks.html
- In the
variables.tf
file:
variable "list_to_iterate" {
description = "A list to iterate on"
type = list(string)
default = []
}
- In the
main.tf
file:
resource "resource" "local_given_name" {
dynamic "block" {
for_each = var.list_to_iterate
content {
block_arg = local_given_name.value
}
}
}