I'm using Bicep, but I understand the older ARM JSON syntax enough to adapt a solution if someone knows one but not the other. Anyway, I can easily tell if a parameter value is an empty string by just doing this inside of one of my policyRule objects:
policyRule: {
if: {
{
field: '[concat(\'tags[\', parameters(\'tagName\'), \']\')]'
equals: ''
}
}
...rest of rule and then statement
}
or testing existence with exists: false
But how would I check if the value is just a bunch of whitespaces like " "
? I tried modifying the field: value to be this:
[trim(concat(\'tags[\', parameters(\'tagName\'), \']\'))]
But it doesn't appear to work. I can still enter a bunch of spaces and have it pass verification.
Trim
removes only leading and trailing whitespace and I also gave the same one as you've used.
This will remove any leading or trailing whitespace from the parameter value before checking to see if it is empty. If the parameter value only contains whitespace characters, the trim function will convert it to an empty string, triggering the equals: "
condition and failing the policy check.
policyRule: {
if: {
{
field: '[trim(concat(\'tags[\', parameters(\'tagName\'), \']\'))]'
equals: ''
}
}
}
But, you need to use the replace
function with a regular expression to remove all whitespace characters from the parameter value.
You can modify the policy rule as shown below:
policyRule: {
if: {
{
field: '[replace(concat(\'tags[\', parameters(\'tagName\'), \']\'), \'\\s\', \'\')]'
equals: ''
}
}
}