Flatten list obtained from a for loop with 2 lists inside a list: list(list(list(string))) -> list(list(string)

Hi All,

I hope some kind soul can help me with this one, because right now I’m going crazy and it’s likely something simple I’m missing.

I’m trying to construct a dasboard which is essentially json formatted text, therefore, it’s all inside a jsonencode. Here’s a gist of the desired end result:

...
{
    "metrics": [
        [ { "expression": "(m1/2048)*100", "label": "Expression1", "id": "e1" } ],
        [ { "expression": "(m2/2048)*100", "label": "Expression2", "id": "e2" } ],
        [ "AWS/ElastiCache", "FreeableMemory", "CacheClusterId", NODE1, { "id": "m1", "visible": false } ],
        [ "...", NODE2, { "id": "m2", "visible": false } ]
    ],
}
...

So far, I’ve got this working for dashboard widgets with a single metric, and I tried doing something similar for this one, resulting in:

...
{                
    "metrics": [ for node in nodes : 
         [
            [ { "expression": "(m-${node}/${instance_total_memory})*100", "label": "Freeable memory (%): ${node}", "id": "e-${node}", "region": region } ],
            [ "AWS/ElastiCache", "FreeableMemory", "CacheClusterId", node, { "id": "m-${node}", "visible": false } ]
        ]
     ]
}
...

I had to encapsulate the inner 2 lists inside another list because terraform complained about the , and rightfully so.

Now, my issue is that I’ve got a list(list(list(strings))) when AWS is expecting a list(list(string). My question is this:

Is there a way to split this list, ou flatten just one layer, or is there a better way of constructing this in the first place?

Edit:
Simplifying things, using a for loop, I need to produce something that looks like this:

"metrics" : [
  ["item 1", "item 2"],
  ["item 3", "item 4"],
  ["item 5", "item 6"],
  ["item 7", "item 8"]
]

but instead I’m getting;

"metrics" : [
  [
    ["item 1", "item 2"],
    ["item 3", "item 4"]
  ],
  [
    ["item 5", "item 6"],
    ["item 7", "item 8"]
  ]
]

Flatten gives me a list of strings, taking it way too far. I’ve also tried concat, but since I’ve got a list, I’d need to concat the lists inside that list. I’ve tried that with the splat operator, but that didn’t produce the result I’d expect. I was hoping for something like bash’s “array[@]”

TIA,
PL