ARM template expressions

Expressions can, at times, be confusing to understand. Expressions often look very similar to program statements, so it can be difficult to distinguish a statement from an expression, and so on. Expressions are written to be evaluated at runtime before returning a value; the value can only be ascertained at runtime. Statements, however, are program code that are executed to perform an action, such as assignments and looping. An expression is comprised of variables, operators, literals, and functions that work together to generate runtime values.

Generally, we declare variables using a specific data type and then use that variable at multiple points within the program. Expressions are similar to variables; however, the variable itself is instead constructed and evaluated at runtime.

Let's understand expressions with the help of an example, as follows:

"count": "[length(parameters('resourceGroupInfo'))]"

In the preceding example, the value of the count key is dependent on an expression. Here, the expression is using a couple of functions, that is, length and parameters, which are used to find the length of data stored in the resourceGroupInfo parameter. The expression is evaluated at runtime while deploying the template to Azure, and the generated value is then assigned to the count key.

Expressions in ARM templates are written within square brackets, [, at the start of an expression, and ] at the end of an expression. The entire expression should be within double-quotes, "".

The return value from an expression can be any of the following:

  • ARM template-supported data types, including string, Boolean, and integers
  • A JSON object
  • A JSON array