How do I combine something like
[for x in var.variable : { "key" : x , "value" : true}] and { "key" : "*", "value" : true}
Say var.variable is an array/list with values [1,2]
and then I need to perform a jsonencode on the above result in terraform.
I have tried merge, join, concat but somehow nothing seems to work or maybe I dont know how to use them correctly.
I need the final output something like –
[
{
"key" : 1,
"value" : true
},
{
"key" : 2,
"value" : true
},
{
"key" : "*",
"value" : true
},
]
>Solution :
You can do that as follows:
variable "variable" {
default = [1,2]
}
output "test" {
value = jsonencode(concat(
[for x in var.variable : { "key" : x , "value" : true}],
[{ "key" : "*", "value" : true}]))
}