Feat: spread operator for map

I’m finding more and more that I have a map (or a module) that is simply a listing of arguments to another module. Currently I need to either:

  1. refactor the module to take the whole map as its argument – this is only viable when all the values have the exact same provenance, or else the dependency graph quickly becomes tangled and cyclic
  2. unpack the map/module item by item – this can contribute as much as 30% of all lines in my tf code, and obviously has lots of room for typo and other human error

It ends up looking like

module "module_b" {
  source = "../module_b"

  a = local.args.a
  b = local.args.b
  c = local.args.c
  d = local.args.d
}

In this thread I’d like to discuss adding a piece of syntax to improve this situation. Some obvious options:

module "module_b" {
  source = "../module_b"
  
  ...local.args.a  # add a second but similar purpose to the existing ... token
  vars = local.args  # a new meta-argument -- probably not
}

The engine would only accept this when the value is statically determined to be a map with known keys. I believe terraform already has some behaviors of that kind.

If you can think of a more idiomatic notation that’s forward-compatible with current modules, please let me know.

Any thoughts? Is this feasible? Useful? Useless?

I’ve had to do that in the past, too. This boilerplate code problem is frustrating.

I don’t have a thorough enough understanding of Terraform internals to know for certain, but I suspect your proposal wouldn’t be able to work, as Terraform would want to build the dependency tree of data flows, before evaluation of what the map contained. I could be wrong, though.