Module iteration support?

Hi all,

Do you know if there is a plan to support iteration on module ? I really need this feature for a customer :slight_smile:

module "mymodule" {
     source = ""
     for_each = toset(var.customer_types)

     //module properties

Any news ?

Hi @opsrom,

That feature is being developed right now and is planned to be included in Terraform 0.13.

In the meantime, for your current customer, I expect you’ll need to follow a common workaround instead: pass the for_each value in as a normal variable and then add it to all of the resources inside manually yourself. It’s not a great answer of course, but hopefully it lets you solve your problem today.

Although the syntax for repetition of modules is the same as for resources, the implementation is very different and so the work is still underway to make sure that all of the existing Terraform features will still work with it. Therefore it’s not clear at this point when the work will be complete. If you’re interested in some details of the internals here (totally optional, of course!) I wrote a description of some earlier module repetition research in my blog. I’m no longer working directly on this myself – fellow Terraform team members James and Pam are leading the final implementation – but hopefully my earlier article is interesting as an overview of some of (but not all of) the problems they’ve been tackling.