Error: Invalid template interpolation value in nrql using list input variable

I am using terraform to create a new relic dashboard , where one of the widget needs to use a list variable of numbers in where clause .
list variable name : vs
variable decalation
vs {
type = list(number)
default = [1,2,3]
}
So my query looks something like this in a widget :
select avg(a) from b where c in (’${var.vs}’)
I want to the list variable values for ‘c’

I am getting the error :
var.vs is list of number with 3 elements
Cannot include the given value in a string template: string required.

Hi @Prati14,

If you want to include a list value as part of a string template then you’ll need to decide and tell Terraform how to serialize the list as a string.

In this case it seems like New Relic is expecting an SQL-like syntax; I assume the intended result here would be the following:

select avg(a) from b where c in (1, 2, 3)

If your values will always be numbers like this then you can achieve that result using join, like this:

select avg(a) from b where c in (${join(", ", var.vs)})

If you need to use string values then unfortunately I think the problem is more complicated because the New Relic query language seems to require strings to be given in single quotes ' and presumably also requires some sort of escaping of any literal quote values in the string. I’m not familiar with this query language so I’m not sure if this is correct but if the expected syntax is for the strings to be placed in ' markers and literal quotes to be escaped by doubling thme like '' then something like this might work:

select avg(a) from b where c in (${join(", ", [for v in var.vs : "'${replace(v, "'", "''")}'" ])})

For your example default value of vs this would produce the following:

select avg(a) from b where c in ('1', '2', '3')

ok will try and update