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

时间:2020-02-27 11:52:34

标签: azure azure-resource-manager

我有一个用于创建2个文档数据库服务器的arm模板。 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"
            }
        ]
    }
}

这对我绝对没有任何意义。我已经尝试使用Google搜索,但是找不到对该错误的任何引用。奇怪的是,它创建了资源并且可用,但是部署表明资源已失败。

以前有没有人看过这个问题?

1 个答案:

答案 0 :(得分:0)

我已经弄清楚了。 与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')]",