存储队列服务上的ARM模板错误作为可选参数

问题描述

MainTemplate

我正在尝试将队列服务作为具有认空白值的可选参数进行部署,模板首先创建存储帐户,然后将队列服务作为嵌套资源。模板抛出错误消息=部署模板验证失败:'模板资源'[concat(parameters('storageName'),'/ default /',parameters('storagequeues')[copyIndex()])]' 在行'91'和列'9'处无效:语言表达式属性数组索引'0'超出范围。

出于某种原因,架构在条件评估之前先验证嵌套的资源名称。这是预期的行为吗?如果没有,请建议变通。

我尝试使用条件“ condition”:“ [not(contains(parameters('storagequeues'),'none'))]”“,并使用defaultvalue =” none“,它将不会创建队列。它工作正常,但这不是理想的方式。

解决方法

此模板可以在您的存储帐户下创建队列。

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#","contentVersion": "1.0.0.0","parameters": {
    "storageAccountName": {
      "type": "string","metadata": {
        "description": "Specifies the name of the Azure Storage account."
      }
    },"queueName": {
      "type": "string","metadata": {
        "description": "Specifies the name of the blob container."
      }
    },"location": {
      "type": "string","defaultValue": "[resourceGroup().location]","metadata": {
        "description": "Specifies the location in which the Azure Storage resources should be deployed."
      }
    }
  },"resources": [
    {
      "type": "Microsoft.Storage/storageAccounts","apiVersion": "2019-06-01","name": "[parameters('storageAccountName')]","location": "[parameters('location')]","sku": {
        "name": "Standard_LRS","tier": "Standard"
      },"kind": "StorageV2","properties": {
        "accessTier": "Hot"
      },"resources": [
        {
          "type": "queueServices/queues","name": "[parameters('queueName')]","dependsOn": [
            "[parameters('storageAccountName')]"
          ]
        }
      ]
    }
  ]
}

我以前见过此'The language expression property array index '0' is out of bounds.'错误,但原因可能有所不同。我在defaultValue中看不到您的'storagequeue',可能是空数组导致了此问题。您可以参考this