Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using bool parameter type for conditions in Azure Resource Manager (ARM) templates

In an ARM Template with a following parameter:

{
  "$schema": "...",
  "contentVersion": "1.0.0.0",
  "parameters": {

  ...

    "SkipThisComponent": {
      "type": "bool"

   ...
}

how would one use it inside a resource condition?

"resources": [
    {
      "apiVersion": "...",
      "name": "...",
      "type": "...",
      "condition": "[???]",

I tried out several approaches, but it seems that equals supports only [int, string, array, or object], if needs both the condition and values to match it to etc. I didn't find a nice clean approach, all seem to be workarounds with casting...

like image 963
Denis Biondic Avatar asked Jun 06 '18 11:06

Denis Biondic


People also ask

Can Azure resource Manager templates contain parameters?

Parameters. In the parameters section of the template, you specify which values you can input when deploying the resources. You're limited to 256 parameters in a template. You can reduce the number of parameters by using objects that contain multiple properties.

How do you use parameters in ARM template?

In the file, you provide the parameter values you want to pass in during deployment. Within the parameter file, you provide values for the parameters in your template. The name of each parameter in your parameter file needs to match the name of a parameter in your template.

What is the difference between variables and parameters in an Azure ARM template?

Parameters will prompt the user for the values unless they are hardcoded. Variables are used to have a single point where information is declared rather than repeating that value all the way through a template.

What type of syntax is used with Azure ARM templates?

The basic syntax of the Azure Resource Manager template (ARM template) is JavaScript Object Notation (JSON). However, you can use expressions to extend the JSON values available within the template.


1 Answers

You can just use the variable within the condition:

"condition" : "[not(variables('SkipThisComponent'))]"
"condition" : "[variables('CreateThisComponent')]"

Logic Functions Ref.

like image 168
Martin Brandl Avatar answered Sep 22 '22 20:09

Martin Brandl