【问题标题】:The language expression property '0' can't be evaluated, property name must be a string.' ARM Templates无法评估语言表达式属性“0”,属性名称必须是字符串。 ARM 模板
【发布时间】:2021-11-08 13:51:15
【问题描述】:

我正在尝试创建 cosmos DB 并运行复制功能以在 ARM 模板中创建容器。但我收到了表达式错误。

无法评估语言表达式属性“0”。',对于两个索引

这里是变量部分:

 "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

【问题讨论】:

    标签: azure azure-cosmosdb azure-resource-manager azure-cosmosdb-mongoapi


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

      threeleggedrabbit 解决了这个问题:“这是因为自动缩放和手动相互依赖,这是不应该的。这是工作的。https://gist.github.com/PrakashRajanSakthivel/17cca682ec0aba049561975142e828f7”

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

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

      1. 您可以使用带有defaultValue 的数组参数来代替变量。

      例如:

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

      例如:

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

      可以参考The language expression property '0' can't be evaluated, property name must be a string - ARM Template error while adding Key Vault access policy和ARM templates: The language expression property ‘0’ can’t be evaluated

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多