Use of `merge` Function Without Squashing


Looks like what I want isn’t possible since keys in a map must be unique, so I’m looking for a workaround.

I’ve gotten as far as getting my data into a list of maps:

  paths_spec = [
    for this_one, values in module.api_lambdas :
    if values.paths_spec != {}

which gives me a list(map(map(string))), but I still need to extract all those maps to look like map(map(string)) (along with duplicates) to present somewhere else. I was thinking about using a template file, but I get the following error:

 Cannot include the given value in a string template: string required

Original Question

The documentation for merge states:

If more than one given map or object defines the same key or attribute, then the one that is later in the argument sequence takes precedence.

I didn’t realise until today that an edge case I have means this is not what I want somewhere that I am already using it.

This code:

paths_spec = merge([for this_one in module.api_lambdas : this_one.paths_spec]...)

results in my keys being squashed, such that if I have a key called foobar with different values than another key called foobar, those two keys are merged together. Makes sense, but what I need is for a way to not do that if the other key has different values.

Is that possible?