While trying to create new policy definition using Azure powershell below exception is thrown, kindly let me know if there is error in cmdlet, or the definition file.
New-AzPolicyDefinition : Unexpected character encountered while parsing value: <. Path '', line 0, position 0. At line:1 char:15 + ... efinition = New-AzPolicyDefinition -Name "application-role-tag" -Disp ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : CloseError: (:) [New-AzPolicyDefinition], JsonReaderException + FullyQualifiedErrorId : Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.NewAzurePolicyDefinitionCmdlet
I have used the below command, the policy definition and parameters definition is reference from from azure devops (git) repository,
$definition = New-AzPolicyDefinition -Name "application-role-tag" -DisplayName "Allow resource creation if Application Role tag value in allowed values" -description "Allows resource creation if the Application Role tag is set to one of the following values: webServer, appServer, data." -Policy 'https://company.visualstudio.com/DefaultCollection/Gullfoss/_git/Azure Governance?path=/Policies/Tags/application-role-tag/azurepolicy.rules.json' -Parameter 'https://company.visualstudio.com/DefaultCollection/Gullfoss/_git/Azure Governance?path=/Policies/Tags/application-role-tag/azurepolicy.parameters.json' -Mode Indexed
Policy definition file:
{
"properties": {
"displayName": "Allow resource creation if 'application role' tag value in allowed values",
"policyType": "Custom",
"mode": "Indexed",
"description": "Allows resource creation if the 'application role' tag is set to one of the following values: webserver, appserver, data, gateway, messageBroker.",
"parameters": {},
"policyRule": {
"if": {
"not": {
"field": "tags['applicationRole']",
"in": [
"webServer",
"appServer"
]
}
},
"then": {
"effect": "audit"
}
}
}
}
Policy parameters definition:
{
"parameters": {}
}