Search code examples
azureazure-resource-managerazure-rm-template

Resource Template - Count array items on condition


Is it possible to count the number of items in an array based upon a certain condition in Resource Templates? Similar to how we can use 'Where-Object' within PowerShell. Seems that the 'length' function is only able to count the total number of items.


Solution

  • No, you cannot do that, unless you hack your way through using nested templates. And that is only possible if you want to compare against a specific object, and you would probably need at least 2 levels of indirection.

    And i would generally advice against that, unless there's no other option.

    but if you want to do that, you would need this function, nested deployments and ARM template way of doing conditionals and I would argue that you would need a state parameter in the nested templates to share the state between those.