In order to evaluate an expression inside a template you’ll need to wrap it in ${ ... } markers to tell Terraform you intend to switch into expression mode, rather than literal mode:
With that said, trying to generate JSON with string concatenation (which is what Terraform template are, essentially) will always be tricky to get exactly right, because you need to worry about getting all of the delimiters in the right places and the nesting correct. I’d recommend instead using Terraform’s jsonencode function to generate the final JSON from a normal Terraform data structure, and then the result is guaranteed to have valid JSON syntax:
Terraform supports JSON-like object syntax in the language specifically to enable easy conversion from literal JSON strings into normal Terraform expressions like this, so although the above resembles JSON syntax it’s actually a Terraform object constructor expression passed as an argument to jsonencode. The result will be a string with a JSON serialization of the result of that expression, which will include the generated list of lists in "metrics" which I wrote here with a for expression, the expression equivalent of a template fordirective.