Hi There,
I am trying to pass the list of string to the Parameters value of the azurerm_policy_assignment here is the code:
resource “azurerm_policy_definition” “policy” {
name = var.policy_name
policy_type = var.policy_type
mode = var.policy_mode
display_name = var.display_name
metadata = <<METADATA
{
“category”: “General”
}
METADATA
policy_rule = <<POLICY_RULE
{
“if”: {
“not”: {
“field”: “location”,
“in”: “[parameters(‘allowedLocations’)]”
}
},
“then”: {
“effect”: “[parameters(‘effect’)]”
}
}
POLICY_RULE
parameters = <<PARAMETERS
{
“allowedLocations”: {
“type”: “Array”,
“metadata”: {
“description”: “The list of allowed locations for resources.”,
“displayName”: “Allowed locations”,
“strongType”: “location”
}
},
“effect”: {
“type”: “string”,
“metadata”: {
“description”: “Provide the list of the effect that will take place”,
“displayName”: “Allowed effect that should take place”
},
“allowedValues”: [
“Audit”,
“Deny”,
“Disabled”
]
}
}
PARAMETERS
}
resource “azurerm_policy_assignment” “policy_assignment” {
name = var.policy_assignment_name
scope = var.policy_scope
policy_definition_id = azurerm_policy_definition.policy.id
description = var.policy_description
display_name = var.policy_assignment_name
parameters = <<PARAMETERS
{
“allowedLocations”: {
“value”: “{var.allowedLocations}"
},
"effect": {
"value": "{var.policy_effect}”
}
}
PARAMETERS
}
but I am getting the error as shown below.
Error: Invalid template interpolation value
on Modules/AzurePolicy/main.tf line 69, in resource “azurerm_policy_assignment” “policy_assignment”:
65:
66:
67:
68:
69: “${var.allowedLocations}”
70:
71:
72:
73:
74:
75:
76:
|----------------
| var.allowedLocations is list of string with 4 elements
Cannot include the given value in a string template: string required.
Do you know if I am doing something wrong here or if there is a way to do something like this.