【问题标题】:Create Resource Group Deployment with REST API使用 REST API 创建资源组部署
【发布时间】:2017-09-06 19:33:32
【问题描述】:
PUT /subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}
    /providers/Microsoft.Resources/deployments/{deploymentName}?api-version=2016-09-01

REST 调用主体:

{
    "properties": {
        "template": {
            "schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
            "contentVersion": "1.0.0.0",
            "resources": []
        }
    }
}

这是一个最小的有效 JSON 模板,如果我执行我得到的请求:

{
  "error": {
    "code": "InvalidRequestContent",
    "message": "The request content was invalid and could not be deserialized: 'Could not find member 'schema' on object of type 'Template'. Path 'properties.template.schema', line 4, position 16.'."
  }
}

好的,这没有意义,让我们尝试删除“模式”属性,这就是我得到的:

{
  "error": {
    "code": "InvalidRequestContent",
    "message": "The request content was invalid and could not be deserialized: 'Required property '$schema' not found in JSON. Path 'properties.template', line 6, position 4.'."
  }
}

docs 中没有描述模板对象的架构。那么WTH?

【问题讨论】:

    标签: rest azure


    【解决方案1】:

    根据报错信息我们可能知道需要使用$schema而不是schema,请尝试使用以下body和mode。它在我这边工作正常,我用 fiddler 测试过。

    {
          "properties": {
            "template": {
              "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
              "contentVersion": "1.0.0.0",
              "resources": []
            },
            "mode": "Incremental"
          }
    
    }
    

    【讨论】:

    • 你知道如何对 New-AzureRmResource 做同样的事情吗?
    • `如何用 New-AzureRmResource 做同样的事情?`你能解释一下吗?
    • 如何使用 New-AzureRmResource 创建部署,我尝试执行相同的调用,但无法处理模板。我知道有一个 cmdlet 可以做到这一点,但这是不可能的
    • 如果有用,请标记为答案。如果您还有其他问题,请在使用 cmdlet 时发布另一个带有详细异常信息的 SO Thread。
    • 我还没有测试过,所以不知道它是否有用,只是问
    猜你喜欢
    • 2019-07-15
    • 1970-01-01
    • 1970-01-01
    • 2021-02-27
    • 2017-04-05
    • 1970-01-01
    • 2018-07-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多