使用 DevOps 部署 ARM 模板时出现奇怪的错误

Strange error when deploying ARM templates using DevOps

我有一个 arm 模板,可以创建 2 个文档数据库服务器。 ARM 模板部分如下所示:

{
  "name": "[variables('sqlServerName')]",
  "type": "Microsoft.DocumentDB/databaseAccounts",
  "apiVersion": "2019-12-12",
  "location": "[parameters('location')]",
  "tags": {
    "name": "Cosmos DB Account"
  },
  "properties": {
    "locations": "[variables('locations')]",
    "databaseAccountOfferType": "Standard"
  }
},
{
  "name": "[variables('sqlServerDevelopmentName')]",
  "type": "Microsoft.DocumentDB/databaseAccounts",
  "apiVersion": "2019-12-12",
  "location": "[parameters('location')]",
  "tags": {
    "name": "Cosmos Development DB Account"
  },
  "properties": {
    "locations": "[variables('locations')]",
    "databaseAccountOfferType": "Standard"
  }
},
{
  "type": "Microsoft.DocumentDB/databaseAccounts/apis/databases",
  "name": "[concat(variables('sqlServerName'), '/sql/', variables('name'))]",
  "apiVersion": "2016-03-31",
  "dependsOn": ["[resourceId('Microsoft.DocumentDB/databaseAccounts/', variables('sqlServerName'))]"],
  "properties": {
    "resource": {
      "name": "[variables('liveName')]"
    },
    "options": {
      "throughput": "[variables('cosmosThroughPut')]"
    }
  }
},
{
  "type": "Microsoft.DocumentDB/databaseAccounts/apis/databases",
  "name": "[concat(variables('sqlServerDevelopmentName'), '/sql/', variables('name'))]",
  "apiVersion": "2016-03-31",
  "dependsOn": ["[resourceId('Microsoft.DocumentDB/databaseAccounts/', variables('sqlServerDevelopmentName'))]"],
  "properties": {
    "resource": {
      "name": "[variables('developmentName')]"
    },
    "options": {
      "throughput": "[variables('cosmosDevelopThroughPut')]"
    }
  }
},
{
  "name": "[concat(variables('sqlServerName'), '/sql/', variables('name'), '/', variables('cosmosContainerName'))]",
  "type": "Microsoft.DocumentDb/databaseAccounts/apis/databases/containers",
  "apiVersion": "2016-03-31",
  "dependsOn": ["[resourceId('Microsoft.DocumentDB/databaseAccounts/apis/databases', variables('sqlServerName'), 'sql', variables('name'))]"],
  "properties": {
    "resource": {
      "name": "[variables('cosmosContainerName')]",
      "partitionKey": {
        "paths": [
          "/categoryId"
        ],
        "kind": "Hash"
      },
      "indexingPolicy": {
        "indexingMode": "consistent",
        "includedPaths": [{
          "path": "/*"
        }]
      }
    }
  }
},
{
  "name": "[concat(variables('sqlServerDevelopmentName'), '/sql/', variables('name'), '/', variables('cosmosContainerName'))]",
  "type": "Microsoft.DocumentDb/databaseAccounts/apis/databases/containers",
  "apiVersion": "2016-03-31",
  "dependsOn": ["[resourceId('Microsoft.DocumentDB/databaseAccounts/apis/databases', variables('sqlServerDevelopmentName'), 'sql', variables('name'))]"],
  "properties": {
    "resource": {
      "name": "[variables('cosmosContainerName')]",
      "partitionKey": {
        "paths": [
          "/categoryId"
        ],
        "kind": "Hash"
      },
      "indexingPolicy": {
        "indexingMode": "consistent",
        "includedPaths": [{
          "path": "/*"
        }]
      }
    }
  }
}

变量如下所示:

"name": "sxp",
"sqlServerName": "[variables('liveName')]",
"sqlServerDevelopmentName": "[variables('developmentName')]",
"sxpDatabaseName": "[variables('name')]",
"cosmosContainerName": "products",
"cosmosThroughPut": "400",
"cosmosDevelopThroughPut": "400",

当我 运行 我的版本我得到这个错误(对于两个 DocumentDb 服务器):

{
    "status": "Failed",
    "error": {
        "code": "ResourceDeploymentFailure",
        "message": "The resource operation completed with terminal provisioning state 'Failed'.",
        "details": [
            {
                "code": "BadRequest",
                "message": "Message: {\"code\":\"BadRequest\",\"message\":\"Message: {\\"partitionCount\\":1}\r\nActivityId: b0751976-2076-4f29-93ab-b3d5849390b8, Request URI: /apps/0ccd856f-da7a-4ff9-a530-88ce0dbfd50c/services/b3350877-fd5e-4ea1-b6ee-41ecb9fb2540/partitions/14300278-223a-4614-afca-48f66e186695/replicas/132272757678585484p, RequestStats: , SDK: Microsoft.Azure.Documents.Common/2.9.2\"}, Request URI: /dbs, RequestStats: , SDK: Microsoft.Azure.Documents.Common/2.9.2, Microsoft.Azure.Documents.Common/2.9.2, Microsoft.Azure.Documents.Common/2.9.2, Microsoft.Azure.Documents.Common/2.9.2, Microsoft.Azure.Documents.Common/2.9.2, Microsoft.Azure.Documents.Common/2.9.2, Microsoft.Azure.Documents.Common/2.9.2, Microsoft.Azure.Documents.Common/2.9.2, Microsoft.Azure.Documents.Common/2.9.2"
            }
        ]
    }
}

这对我来说毫无意义。我试过用谷歌搜索它,但找不到对错误的任何引用。奇怪的是,它创建了资源并且它们是可用的,但是部署说它失败了。

有人以前见过这个问题吗?

我已经弄明白了。 这与 id 属性 有关。你必须有一个。如果你使用 arm-ttk-master 它会告诉你不使用 resourceId 函数是无效的,但是对于 cosmos 数据库和容器,这是错误的.... .

所以,它应该是这样的:

{
  "type": "Microsoft.DocumentDB/databaseAccounts/apis/databases",
  "name": "[concat(variables('sqlServerDevelopmentName'), '/sql/', variables('name'))]",
  "apiVersion": "2016-03-31",
  "dependsOn": [
    "[resourceId('Microsoft.DocumentDB/databaseAccounts', variables('sqlServerDevelopmentName'))]"
  ],
  "properties": {
    "resource": {
      "id": "[variables('name')]"
    },
    "options": {
      "throughput": "[variables('cosmosDevelopThroughPut')]"
    }
  }
},
{
  "name": "[concat(variables('sqlServerName'), '/sql/', variables('name'), '/', variables('cosmosContainerName'))]",
  "type": "Microsoft.DocumentDb/databaseAccounts/apis/databases/containers",
  "apiVersion": "2016-03-31",
  "dependsOn": [
    "[resourceId('Microsoft.DocumentDB/databaseAccounts/apis/databases', variables('sqlServerName'), 'sql', variables('name'))]"
  ],
  "properties": {
    "resource": {
      "id": "[variables('cosmosContainerName')]",
      "partitionKey": {
        "paths": [
          "/categoryId"
        ],
        "kind": "Hash"
      },
      "indexingPolicy": {
        "indexingMode": "consistent",
        "includedPaths": [{
          "path": "/*"
        }]
      }
    }
  }
},

记下 id 属性:

"id": "[variables('cosmosContainerName')]",