简体   繁体   中英

How to use conditional OR in arm template?

I'm trying to create a private endpoint through an ARM template for a storage account if the storage account SKU is Standard_GRS or Standard_RAGRS, or Standard_GZRS. How to include this in the conditional statement in the ARM template.

We have tested this in our local environment, below statements are based on our analysis.

In our local environment, we have created an ARM template to deploy storage account a condition the SKU of the storage account should be either of the below:

  • "Standard_GRS", "Standard_RAGRS", "Standard_GZRS"

To achieve this we have used the below condition in our ARM template:

"condition":"[or(equals(parameters('sku'),'Standard_RAGRS'),equals(parameters('sku'),'Standard_GZRS'),equals(parameters('sku'),'Standard_GRS'))]",

Here is the ARM template that we have used:

    {
        "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
        "contentVersion": "1.0.0.0",
        "parameters": {
            "sku": {
                "type": "string"
            }
        },
        "functions": [],
        "variables": {
        },
        "resources": [
      {
         "condition":"[or(equals(parameters('sku'),'Standard_RAGRS'),equals(parameters('sku'),'Standard_GZRS'),equals(parameters('sku'),'Standard_GRS'))]",
          "name": "<strgaccount>",
          "type": "Microsoft.Storage/storageAccounts",
          "apiVersion": "2021-04-01",
          "tags": {
              "displayName": "storageaccount1"
          },
          "location": "[resourceGroup().location]",
          "kind": "StorageV2",
          "sku": {
              "name": "[parameters('sku')]"
          }
      }
        ],
        "outputs": {}
    }

Here is the sample output for reference:

  • In the below Output we have passed the SKU value "Standard_GZRS" the condition got succeeded and Resource got deployed.

在此处输入图像描述

  • In the below Output we have passed the SKU value "Standard_LRS" the condition got failed & the resource didn't get deployed.

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM