Azure policy Error

Hey,
I need to create this Azure Policy definition:

resource “azurerm_policy_definition” “AKS-Confingure-Diagnostic-settings” {
name = “AKS-Confingure-Diagnostic-settings”
policy_type = “Custom”
mode = “Indexed”
display_name = “Configure diagnostic settings for Azure Kubernetes Service to Log Analytics workspace”
management_group_id = var.managementGroupId

metadata = <<METADATA
{
“category”: “Azure Kubernetes Services”
}

METADATA

policy_rule = <<POLICY_RULE
{
“if”: {
“field”: “type”,
“equals”: “Microsoft.ContainerService/managedClusters”
},
“then”: {
“effect”: “[parameters(‘effect’)]”,
“details”: {
“type”: “Microsoft.Insights/diagnosticSettings”,
“roleDefinitionIds”: [
“/providers/microsoft.authorization/roleDefinitions/749f88d5-cbae-40b8-bcfc-e573ddc772fa”,
“/providers/microsoft.authorization/roleDefinitions/92aaf0da-9dab-42b6-94a3-d43ce8d16293”
],
“existenceCondition”: {
“allOf”: [
{
“count”: {
“value”: [
{
“category”: “kube-apiserver”,
“enabled”: “[parameters(‘kube-apiserver’)]”
},
{
“category”: “kube-audit”,
“enabled”: “[parameters(‘kube-audit’)]”
},
{
“category”: “kube-controller-manager”,
“enabled”: “[parameters(‘kube-controller-manager’)]”
},
{
“category”: “kube-scheduler”,
“enabled”: “[parameters(‘kube-scheduler’)]”
},
{
“category”: “cluster-autoscaler”,
“enabled”: “[parameters(‘cluster-autoscaler’)]”
},
{
“category”: “kube-audit-admin”,
“enabled”: “[parameters(‘kube-audit-admin’)]”
},
{
“category”: “guard”,
“enabled”: “[parameters(‘guard’)]”
},
{
“category”: “cloud-controller-manager”,
“enabled”: “[parameters(‘cloud-controller-manager’)]”
},
{
“category”: “csi-azuredisk-controller”,
“enabled”: “[parameters(‘csi-azuredisk-controller’)]”
},
{
“category”: “csi-azurefile-controller”,
“enabled”: “[parameters(‘csi-azurefile-controller’)]”
},
{
“category”: “csi-snapshot-controller”,
“enabled”: “[parameters(‘csi-snapshot-controller’)]”
}
],
“name”: “logCategoriesParameter”,
“where”: {
“count”: {
“field”: “Microsoft.Insights/diagnosticSettings/logs[]",
“where”: {
“allOf”: [
{
“field”: "Microsoft.Insights/diagnosticSettings/logs[
].enabled”,
“equals”: “[current(‘logCategoriesParameter’).enabled]”
},
{
“field”: “Microsoft.Insights/diagnosticSettings/logs[].category",
“equals”: “[current(‘logCategoriesParameter’).category]”
}
]
}
},
“greater”: 0
}
},
“equals”: 11
},
{
“count”: {
“field”: "Microsoft.Insights/diagnosticSettings/metrics[
]”,
“where”: {
“allOf”: [
{
“field”: “Microsoft.Insights/diagnosticSettings/metrics[].category",
“equals”: “AllMetrics”
},
{
“field”: "Microsoft.Insights/diagnosticSettings/metrics[
].enabled”,
“equals”: “[parameters(‘AllMetrics’)]”
}
]
}
},
“greater”: 0
},
{
“field”: “Microsoft.Insights/diagnosticSettings/workspaceId”,
“equals”: “[parameters(‘logAnalytics’)]”
}
]
},
“deployment”: {
“properties”: {
“mode”: “incremental”,
“template”: {
“$schema”: “http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#”,
“contentVersion”: “1.0.0.0”,
“parameters”: {
“diagnosticsSettingNameToUse”: {
“type”: “string”
},
“resourceName”: {
“type”: “string”
},
“logAnalytics”: {
“type”: “string”
},
“location”: {
“type”: “string”
},
“AllMetrics”: {
“type”: “string”
},
“kube-apiserver”: {
“type”: “string”
},
“kube-audit”: {
“type”: “string”
},
“kube-controller-manager”: {
“type”: “string”
},
“kube-scheduler”: {
“type”: “string”
},
“cluster-autoscaler”: {
“type”: “string”
},
“kube-audit-admin”: {
“type”: “string”
},
“guard”: {
“type”: “string”
},
“cloud-controller-manager”: {
“type”: “string”
},
“csi-azuredisk-controller”: {
“type”: “string”
},
“csi-azurefile-controller”: {
“type”: “string”
},
“csi-snapshot-controller”: {
“type”: “string”
}
},
“variables”: {},
“resources”: [
{
“type”: “Microsoft.ContainerService/managedClusters/providers/diagnosticSettings”,
“apiVersion”: “2017-05-01-preview”,
“name”: “[concat(parameters(‘resourceName’), ‘/’, ‘Microsoft.Insights/’, parameters(‘diagnosticsSettingNameToUse’))]”,
“location”: “[parameters(‘location’)]”,
“dependsOn”: ,
“properties”: {
“workspaceId”: “[parameters(‘logAnalytics’)]”,
“metrics”: [
{
“category”: “AllMetrics”,
“enabled”: “[parameters(‘AllMetrics’)]”
}
],
“logs”: [
{
“category”: “kube-apiserver”,
“enabled”: “[parameters(‘kube-apiserver’)]”
},
{
“category”: “kube-audit”,
“enabled”: “[parameters(‘kube-audit’)]”
},
{
“category”: “kube-controller-manager”,
“enabled”: “[parameters(‘kube-controller-manager’)]”
},
{
“category”: “kube-scheduler”,
“enabled”: “[parameters(‘kube-scheduler’)]”
},
{
“category”: “cluster-autoscaler”,
“enabled”: “[parameters(‘cluster-autoscaler’)]”
},
{
“category”: “kube-audit-admin”,
“enabled”: “[parameters(‘kube-audit-admin’)]”
},
{
“category”: “guard”,
“enabled”: “[parameters(‘guard’)]”
},
{
“category”: “cloud-controller-manager”,
“enabled”: “[parameters(‘cloud-controller-manager’)]”
},
{
“category”: “csi-azuredisk-controller”,
“enabled”: “[parameters(‘csi-azuredisk-controller’)]”
},
{
“category”: “csi-azurefile-controller”,
“enabled”: “[parameters(‘csi-azurefile-controller’)]”
},
{
“category”: “csi-snapshot-controller”,
“enabled”: “[parameters(‘csi-snapshot-controller’)]”
}
]
}
}
],
“outputs”: {}
},
“parameters”: {
“diagnosticsSettingNameToUse”: {
“value”: “[parameters(‘diagnosticsSettingNameToUse’)]”
},
“logAnalytics”: {
“value”: “[parameters(‘logAnalytics’)]”
},
“location”: {
“value”: “[field(‘location’)]”
},
“resourceName”: {
“value”: “[field(‘name’)]”
},
“guard”: {
“value”: “[parameters(‘guard’)]”
},
“AllMetrics”: {
“value”: “[parameters(‘AllMetrics’)]”
},
“kube-apiserver”: {
“value”: “[parameters(‘kube-apiserver’)]”
},
“kube-audit”: {
“value”: “[parameters(‘kube-audit’)]”
},
“kube-scheduler”: {
“value”: “[parameters(‘kube-scheduler’)]”
},
“kube-controller-manager”: {
“value”: “[parameters(‘kube-controller-manager’)]”
},
“cluster-autoscaler”: {
“value”: “[parameters(‘cluster-autoscaler’)]”
},
“kube-audit-admin”: {
“value”: “[parameters(‘kube-audit-admin’)]”
},
“cloud-controller-manager”: {
“value”: “[parameters(‘cloud-controller-manager’)]”
},
“csi-azuredisk-controller”: {
“value”: “[parameters(‘csi-azuredisk-controller’)]”
},
“csi-azurefile-controller”: {
“value”: “[parameters(‘csi-azurefile-controller’)]”
},
“csi-snapshot-controller”: {
“value”: “[parameters(‘csi-snapshot-controller’)]”
}
}
}
}
}
}
}
POLICY_RULE

parameters = <<PARAMETERS
{
“effect”: {
“type”: “String”,
“metadata”: {
“displayName”: “Effect”,
“description”: “Enable or disable the execution of the policy”
},
“allowedValues”: [
“DeployIfNotExists”,
“Disabled”
],
“defaultValue”: “DeployIfNotExists”
},
“diagnosticsSettingNameToUse”: {
“type”: “String”,
“metadata”: {
“displayName”: “Setting name”,
“description”: “Name of the diagnostic settings.”
},
“defaultValue”: “AzureKubernetesDiagnosticsLogsToWorkspace”
},
“logAnalytics”: {
“type”: “String”,
“metadata”: {
“displayName”: “Log Analytics workspace”,
“description”: “Specify the Log Analytics workspace the Azure Kubernetes Service should be connected to”,
“strongType”: “omsWorkspace”,
“assignPermissions”: true
}
},
“AllMetrics”: {
“type”: “String”,
“metadata”: {
“displayName”: “AllMetrics - Enabled”,
“description”: “Whether to stream AllMetrics logs to the Log Analytics workspace - True or False”
},
“allowedValues”: [
“True”,
“False”
],
“defaultValue”: “True”
},
“kube-apiserver”: {
“type”: “String”,
“metadata”: {
“displayName”: “kube-apiserver - Enabled”,
“description”: “Whether to stream kube-apiserver logs to the Log Analytics workspace - True or False”
},
“allowedValues”: [
“True”,
“False”
],
“defaultValue”: “True”
},
“kube-audit”: {
“type”: “String”,
“metadata”: {
“displayName”: “kube-audit - Enabled”,
“description”: “Whether to stream kube-audit logs to the Log Analytics workspace - True or False”
},
“allowedValues”: [
“True”,
“False”
],
“defaultValue”: “True”
},
“kube-controller-manager”: {
“type”: “String”,
“metadata”: {
“displayName”: “kube-controller-manager - Enabled”,
“description”: “Whether to stream kube-controller-manager logs to the Log Analytics workspace - True or False”
},
“allowedValues”: [
“True”,
“False”
],
“defaultValue”: “True”
},
“kube-scheduler”: {
“type”: “String”,
“metadata”: {
“displayName”: “kube-scheduler - Enabled”,
“description”: “Whether to stream kube-scheduler logs to the Log Analytics workspace - True or False”
},
“allowedValues”: [
“True”,
“False”
],
“defaultValue”: “True”
},
“cluster-autoscaler”: {
“type”: “String”,
“metadata”: {
“displayName”: “cluster-autoscaler - Enabled”,
“description”: “Whether to stream cluster-autoscaler logs to the Log Analytics workspace - True or False”
},
“allowedValues”: [
“True”,
“False”
],
“defaultValue”: “True”
},
“kube-audit-admin”: {
“type”: “String”,
“metadata”: {
“displayName”: “kube-audit-admin - Enabled”,
“description”: “Whether to stream kube-audit-admin logs to the Log Analytics workspace - True or False”
},
“allowedValues”: [
“True”,
“False”
],
“defaultValue”: “True”
},
“guard”: {
“type”: “String”,
“metadata”: {
“displayName”: “guard - Enabled”,
“description”: “Whether to stream guard logs to the Log Analytics workspace - True or False”
},
“allowedValues”: [
“True”,
“False”
],
“defaultValue”: “True”
},
“cloud-controller-manager”: {
“type”: “String”,
“metadata”: {
“displayName”: “cloud-controller-manager - Enabled”,
“description”: “Whether to stream cloud-controller-manager logs to the Log Analytics workspace - True or False”
},
“allowedValues”: [
“True”,
“False”
],
“defaultValue”: “True”
},
“csi-azuredisk-controller”: {
“type”: “String”,
“metadata”: {
“displayName”: “csi-azuredisk-controller - Enabled”,
“description”: “Whether to stream csi-azuredisk-controller logs to the Log Analytics workspace - True or False”
},
“allowedValues”: [
“True”,
“False”
],
“defaultValue”: “True”
},
“csi-azurefile-controller”: {
“type”: “String”,
“metadata”: {
“displayName”: “csi-azurefile-controller - Enabled”,
“description”: “Whether to stream csi-azurefile-controller logs to the Log Analytics workspace - True or False”
},
“allowedValues”: [
“True”,
“False”
],
“defaultValue”: “True”
},
“csi-snapshot-controller”: {
“type”: “String”,
“metadata”: {
“displayName”: “csi-snapshot-controller - Enabled”,
“description”: “Whether to stream csi-snapshot-controller logs to the Log Analytics workspace - True or False”
},
“allowedValues”: [
“True”,
“False”
],
“defaultValue”: “True”
}
}
PARAMETERS

}

And i was add this definition to set definition as well:

resource “azurerm_policy_set_definition” “initiative” {
name = var.initiative_name
policy_type = “Custom”
display_name = var.initiative_name
management_group_id = var.managementGroupId

parameters = <<PARAMETERS
{
“logAnalytics”: {
“type”: “string”,
“metadata”: {
“displayName”: “Log Analytics workspace”,
“description”: “Specify the Log Analytics workspace the Azure Kubernetes Service should be connected to”
},
“defaultValue”: “${var.loganalyticsworkspacename}”
}
}
PARAMETERS

policy_definition_reference {
policy_definition_id = azurerm_policy_definition.AKS-Confingure-Diagnostic-settings.id
parameter_values = <<VALUE
{
“logAnalytics”: {“value”: “abc”}
}
VALUE
}
Blockquote

And i have got this error:

Error: creating Policy Assignment ID: (Assignment Name “Kubernetes assigenment” / Scope “/providers/Microsoft.Management/managementGroups/Sancy.AssignmentsClient#Create: Failure responding to request: StatusCode=400 – Original Error: autorest/azure: Service returned an error. StatuseterType” Message=“The policy parameter ‘logAnalytics’ does not match the expected parameter type defined in the policy definition ‘Kubernetes ected policy parameter type: ‘String’. The actual policy parameter type ‘Array’.’.”

WHY???
the parameter is STRING, why Terraform think it is Array???

Thanks