Azure / Azure/azure-cli

az policy definition create erroring if rule contains nested functions

Open
#22,884 1 comment 0 reactions 2 assignees Claimed by @jiasli View on GitHub
act-identity-squad ARM Auto-Assign customer-reported
Dominant language
Python
Stars
4.6k
Forks
3.5k
Avg merge
3d 2h
Merged PRs (30d)
60

Description

**Related command**
```
function Get-SafeJson([string]$inputJson){
$value = $inputJson -replace " ", ""
$value = $value -replace "`r`n", ""
return $value
}
$policyInfo = @{
Data = @{name = "test";displayName="test"; description="";mode="All"}
Rules =Get-Content "policy_rules.json" -Raw;
Parameters=Get-Content "policy_params.json" -Raw;
}
az policy definition create -n $($policyInfo.Data.name) --display-name "$($policyInfo.Data.displayName)" --description "$($policyInfo.Data.description)" --mode "$($policyInfo.Data.mode)" --rules "$(Get-SafeJson $($policyInfo.Rules))" -- params "$(Get-SafeJson $($policyInfo.Parameters))"
```
**Describe the bug**
Error: az : ]\",\"field\": \"[concat('tags[' was unexpected at this time.

**To Reproduce**
Create file policy_rules.json with rule definition where rule contains following (sorry, I can't past full file, it contains sensitive info, but this file is based on https://docs.microsoft.com/en-us/azure/governance/policy/samples/pattern-tags ):
```
"if": {
"allof": [
{
"equals": "Microsoft.Web/serverfarms",
"field": "type"
},
{
"not": {
"equals": "[parameters('tagValue')]",
"field": "[concat('tags[',parameters('tagName'), ']')]"
}
},
{
"field": "location",
"in": "[parameters('azureregions')]"
}
]
}
... more here
```

`[concat('tags[',parameters('tagName'), ']')]` is valid structure for the rule definition, it works fine in the portal.
Also works in REST API.

**Expected behavior**
no errors

**Environment summary**
Install method: MSI
CLI: 2.37.0
Shell: PowerShell (ISE)

**Additional context**

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.