title: Terraform: Pass a variable containing a list of strings to a jsonencode section
body: <p>I want to set up a Terraform module that assigns a policy to an Azure resource according to Terraforms <a href="https://www.terraform.io/docs/providers/azurerm/r/policy_assignment.html" rel="noreferrer">policy assignment example</a>. </p>
  
  <p>In order to assign the allowed locations policy, I want to pass the list of allowed locations as a list of strings from the variables.tf file to the main.tf, where the assignment is executed.</p>
  
  <h3>main.tf</h3>
  
  <pre><code>#Allowed Locations Policy Assignment 
  resource "azurerm_policy_assignment" "allowedlocations" {
    name                 = "allowed-locations"
    scope                = var.scope_allowedlocations
    policy_definition_id = var.policy_allowedlocations.id 
    description          = "This policy enables you to restrict the locations."
    display_name         = "Allowed Locations"
  
    parameters = &lt;&lt;PARAMETERS
    {
    "allowedLocations": {
      "value": ${var.listofallowedlocations}
      }
    } 
    PARAMETERS
  
  }
  </code></pre>
  
  <h3>variables.tf</h3>
  
  <pre><code># Scope of the Allowed Locations policy
  variable "scope_allowedlocations" {
    description = "The scope of the allowed locations assignment."
    default     = "Subscription"
  }
  
  # Scope of the Allowed Locations policy
  variable "policy_allowedlocations" {
    description = "The allowed locations policy (created by the policy-define module)."
    default     = "default"
  }
  
  # List of the Allowed Locations
  variable "listofallowedlocations" {
    type = list(string)
    description = "The allowed locations list."
    default     = [ "West Europe", "North Europe", "East US" ]
  }
  </code></pre>
  
  <p>Executing with <code>terraform plan</code> leads to the following error:</p>
  
  <pre><code>Error: Invalid template interpolation value
  
    on modules/policy-assign/main.tf line 16, in resource "azurerm_policy_assignment" "allowedlocations":
    12:
    13:
    14:
    15:
    16:     "value": ${var.listofallowedlocations}
    17:
    18:
    19:
      |----------------
      | var.listofallowedlocations is list of string with 3 elements
  
  Cannot include the given value in a string template: string required.
  </code></pre>
  
  <p>Thus, I don't know how to exactly pass the list from the variables file to the PARAMETERS section of the policy assignment resource. In Terraforms <a href="https://www.terraform.io/docs/providers/azurerm/r/policy_assignment.html" rel="noreferrer">policy assignment example</a> the list is directly inline coded in the PARAMETERS section and it works. But there is no passing of variables...:</p>
  
  <pre><code>parameters = &lt;&lt;PARAMETERS
  {
    "allowedLocations": {
      "value": [ "West Europe" ]
    }
  }
  PARAMETERS
  </code></pre>