But I am getting a few different errors one of which is Error: status: 422, body: [{"fieldNames":["Dashboard"],"classification":"RequiredError","message":"Required"}]
However, I think this is a red herring as if I remove the jsonencode loop then the dashboard can be applied fine. So I believe I am not formatting this section correctly.
Is there anything I am doing wrong when using jsonencode?
There is not enough context here to be able to advise.
You should change your Terraform code temporarily for testing so you can see the entire generated JSON and compare it to what you expected - for example by assigning it to a local variable and using terraform console to view it.
So it looks like TF is adding a trailing comma which I suspect might be breaking it. I can see this in the plan
After the last + type = "query" there should not be a trailing comma. Do you know of anyway to get round this? Thanks for the reply.
Technically you are correct as this is the output of terraform plan and it is rendering the json as HCL.
The question still remains, it is adding a trailing comma which is causing the apply to fail. Is there a way to prevent the trailing comma?