Within #Terraform Providers, we can define a resource in such a way we could replicate multiple instances of them under different name. A recommended way to do this is by using a Terraform Meta Arguments# for_each
. for_each
will store a list of values, of type# set or map, into a variable called each.value
. The following shows the configuration# example:
# In resource file
resource ... {
filename = each.value
for_each = toset(var.users)
}
# In variables.tf
variable users {
type = list(string)
defaults = [
...
]
}
Note: We can convert list to set with the built-in function toset()
.