Templatefile to generate json with variables


I am creating a policy with templatefile. When I create a policy with multiple variables, I get an error:

My code:

resource "aws_organizations_policy" "staging-rnd-security-shared-production" {
  name = "staging-rnd-security-shared-production"
  content = templatefile("../templates/l5-environment-template.json",{
    VAR_ENVIRONMENT = var.l5_OU,
    VAR_ROLES = var.roles,
    VAR_ACCOUNT_ID = var.account

ROLES is a list and others are string.


│ Call to function "templatefile" failed: ../templates/l5-environment-template.json:84,32-41: Invalid template interpolation value; Cannot include the given value in a string template:    
│ string required., and 3 other diagnostic(s).

Any idea, how I can generate json policy with multiple variables including list?

Hi @Tyroform,

This seems to be a problem in the template itself, rather than in the call to the template.

Could you add another comment including the contents of that ../templates/l5-environment-template.json file? Thanks!