How do I specify integer as requirement for Azure Policy?

Gregory Suvalian 186 Reputation points
2020-10-21T18:44:25.097+00:00

I have Azure policy which refuses to evaluate expression of with error below. I assume the problem is that when you provide tag values in portal they passed as a string

{
 "field": "tags['Longevity']",
 "less": 1
}

Error

"The policy assignment 'd9c1d0b06de841559a1cbafe' associated with the policy definition 'dee67dc2-7393-4c02-916f-92511146c970' could not be evaluated. 
A 'less' or 'lessOrEquals' or 'greater' or 'greaterOrEquals' expression expects operands of same type for comparison. The supported types are string, integer, float, ISO 8601 datetime. Please either fix the 
policy or remove the policy assignment to unblock. See https://aka.ms/policy-conditions for usage details."

uiBmM.png

Azure Policy
Azure Policy
An Azure service that is used to implement corporate governance and standards at scale for Azure resources.
918 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. tbgangav-MSFT 10,416 Reputation points
    2020-10-22T12:40:00.93+00:00

    Hi @Gregory Suvalian ,

    I see that this question is a duplicate of this Stack Overflow question. Glad to know that it worked. :)

    Just sharing for the benefit of broader audience who might be looking for an answer here.

    For your reference, below is the same content that is copied from the source i.e., from Stack Overflow conversation:

    Microsoft support provided an answer.
    Answer is below which works as expected. Have to use concat() function looks like to escape complain about square brackets inside square brackets

       {  
        "value": "[int(field(concat('tags[', 'Longevity', ']')))]",  
        "less": 0  
       },  
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.