Dynamically pass a map as the module attributes in terraform 12/13?

817 views Asked by At

Question

How to you dynamically unpack a map into a module/resource attributes? I understand you can do dynamic resource attributes blocks in terraform 12/13, but can you do it for all the attributes for the entire resource/module? For example:

module "this" {
  for_each = {
    att0 = "attr0"
    attr1 = "attr1"
    attr2 = "attr2"
  }

  each.key = each.value
}

# my hope is that this would do the equivalent of this code below

module "this" {
  attr0 = "attr0"
  attr1 = "attr1"
  attr2 = "attr2"
}

similiar to how you would do it in python with the splat kwargs into a function. e.g.

# python3
kwargs = {"foo": "bar", "bar": "foo"}
my_func(**kwargs)

other variations that I have tried:

module "this" {
  for_each = {
    att0 = "attr0"
    attr1 = "attr1"
    attr2 = "attr2"
  }
}
module "this" {
  {
    att0 = "attr0"
    attr1 = "attr1"
    attr2 = "attr2"
  }
}
0

There are 0 answers