无法计算语言表达式 属性 '0',属性 名称必须是字符串。' ARM 模板

The language expression property '0' can't be evaluated, property name must be a string.' ARM Templates

我正在尝试创建 cosmos DB 和 运行 复制函数以在 ARM 模板中创建容器。但是我遇到了表达式错误。

The language expression property '0' can't be evaluated.', for both indexes

这里是变量部分:

 "autoscaleOptions" : {
        "copy": [
        {
          "name": "autoscaleSettings",
          "count": "[length(parameters('containers'))]",
          "input": {
          "throughput": "[parameters('containers')[copyIndex('autoscaleSettings')].throughput]",
            "autoscaleSettings": {
              "maxThroughput": "[if(parameters('containers')[copyIndex('autoscaleSettings')].autoscale, null(), parameters('containers')[copyIndex('autoscaleSettings')].maxThroughput)]"
            }
          }
        }
        ]
      }

我如何调用变量:

{
        "type": "Microsoft.DocumentDb/databaseAccounts/mongodbDatabases/collections",
        "apiVersion": "2021-04-15",
        "name": "[format('{0}/{1}/{2}', variables('accountName_var'), parameters('databaseName'), parameters('containers')[copyIndex()].name)]",
        "copy": {
          "count": "[length(parameters('containers'))]",
          "name": "ContainerCopy"
        },
        "properties": {
          "resource": {
            "id": "[parameters('containers')[copyIndex('ContainerCopy')].name]"
          },
          "options": "[variables('autoscaleOptions')[copyIndex('ContainerCopy')].input]"
          
        },
        "dependsOn": [
          "[resourceId('Microsoft.DocumentDB/databaseAccounts/mongodbDatabases', variables('accountName_var'), parameters('databaseName'))]",
          "[resourceId('Microsoft.DocumentDB/databaseAccounts', variables('accountName_var'))]"
        ]
      }

我在这里上传了包含所有参数的整个模板。 https://gist.github.com/PrakashRajanSakthivel/cc2495e82102d9c9569461eb4a96c75f

我能够实现它,这是因为自动缩放和手动依赖彼此,而这本不应该。这是工作的。 https://gist.github.com/PrakashRajanSakthivel/17cca682ec0aba049561975142e828f7

threeleggedrabbit solved this issue: "it's because of the autoscale and manual depends on one another which shouldn't. here is the working one. https://gist.github.com/PrakashRajanSakthivel/17cca682ec0aba049561975142e828f7 "

对于替代解决方案,您可以尝试以下两种方式:

谢谢ngruson and Stringfellow。将您的建议作为答案发布,以帮助其他社区成员。

  1. 您可以使用带有 defaultValue 的数组参数而不是变量。

例如:

"parameters": {
    "functionAccess": {
      "type": "array",
      "defaultValue": [
        "value1",
        "value2",
        "value3"
      ]
    }
  }
  1. 您也可以在copy操作中使用functionAccessArray进行迭代。

例如:

"variables": {
    "functionAccessCsv": "Function-0,Function-1,false,Function-4,false,Function-6,Function-7",
    "functionAccessFiltered": "[replace(replace(variables('functionAccessCsv'), 'false', ''), ',,', ',')]",
    "functionAccessArray": "[split(variables('functionAccessFiltered'), ',')]"
  },

可以参考 and ARM templates: The language expression property ‘0’ can’t be evaluated