使用 ARM 模板部署 API 管理服务时出现问题,它是 APIs

Problem with deploying using ARM Template for API Management Service and it's APIs

我正在尝试使用 ARM 模板部署 Azure API 管理服务及其关联的 API。这里的目标是能够轻松地提供 API 管理服务的新实例及其关联的 APIs 及其所有设置,但能够通过使用参数更改后端 url。为此,我使用 Azure 门户导出了一个模板,并根据我的需要将其更改为能够传入后端 url 作为参数。但是,我 运行 遇到了一些问题:

模板部署返回以下错误:

更新:评论帮助我解决了这个问题。请立即忽略此错误。

16:12:24 - 4:11:50 PM - Resource Microsoft.ApiManagement/service/subscriptions 'testAPITalhaNEW1/master' failed with message '{
16:12:24 -   "error": {
16:12:24 -     "code": "ValidationError",
16:12:24 -     "message": "One or more fields contain incorrect values:",
16:12:24 -     "details": [
16:12:24 -       {
16:12:24 -         "code": "ValidationError",
16:12:24 -         "target": "scope",
16:12:24 -         "message": "Subscription scope should be one of '/apis', '/apis/{apiId}', '/products/{productId}'"
16:12:24 -       }
16:12:24 -     ]
16:12:24 -   }
16:12:24 - }'
16:12:24 - 4:11:50 PM - Subscription scope should be one of '/apis', '/apis/{apiId}', '/products/{productId}'
16:12:24 - 4:12:01 PM - Resource Microsoft.ApiManagement/service/groups/users 'testAPITalhaNEW1/administrators/1' failed with message '{
16:12:24 -   "error": {
16:12:24 -     "code": "MethodNotAllowed",
16:12:24 -     "message": "System group membership cannot be changed",
16:12:24 -     "details": null
16:12:24 -   }
16:12:24 - }'
16:12:24 - 4:12:01 PM - Resource Microsoft.ApiManagement/service/groups/users 'testAPITalhaNEW1/developers/1' failed with message '{
16:12:24 -   "error": {
16:12:24 -     "code": "MethodNotAllowed",
16:12:24 -     "message": "System group membership cannot be changed",
16:12:24 -     "details": null
16:12:24 -   }
16:12:24 - }'
16:12:24 - 4:12:01 PM - Resource Microsoft.ApiManagement/service/users 'testAPITalhaNEW1/1' failed with message '{
16:12:24 -   "error": {
16:12:24 -     "code": "MethodNotAllowed",
16:12:24 -     "message": "Cannot modify property for user with built-In role",
16:12:24 -     "details": null
16:12:24 -   }
16:12:24 - }'



最初该行是:

        "scope": "[concat(resourceId('Microsoft.ApiManagement/master', parameters('service_testAPITalha_name')), '/')]",

我改成了:

        "scope": "[concat(resourceId('Microsoft.ApiManagement/apis', parameters('service_testAPITalha_name')), '/')]",

这也没有解决问题。

错误:"Subscription scope should be one of '/apis', '/apis/{apiId}', '/products/{productId}'"

    {
      "type": "Microsoft.ApiManagement/service/subscriptions",
      "apiVersion": "2019-01-01",
      "name": "[concat(parameters('service_testAPITalha_name'), '/master')]",
      "dependsOn": [
        "[resourceId('Microsoft.ApiManagement/service', parameters('service_testAPITalha_name'))]"
      ],
      //Changed from master to apis
      "properties": {
        "scope": "[concat(resourceId('Microsoft.ApiManagement/apis', parameters('service_testAPITalha_name')), '/')]",
        "displayName": "Built-in all-access subscription",
        "state": "active",
        "primaryKey": "a4a0311b7af34f8fad57cdf8e06723fb",
        "secondaryKey": "3bfb52667eb443a0a430e298b402da03",
        "allowTracing": true
      }
    }

错误:MethodNotAllowed:"Cannot modify property for user with built-In role"

 {
      "type": "Microsoft.ApiManagement/service/users",
      "apiVersion": "2019-01-01",
      "name": "[concat(parameters('service_testAPITalha_name'), '/1')]",
      "dependsOn": [
        "[resourceId('Microsoft.ApiManagement/service', parameters('service_testAPITalha_name'))]"
      ],
      "properties": {
        "firstName": "Administrator",
        "email": "xxx@hotmail.com",
        "state": "active",
        "identities": [
          {
            "provider": "Azure",
            "id": "xxx@hotmail.com"
          }
        ],
        "lastName": "[parameters('users_1_lastName')]"
      }
    }

我取出来的邮箱是注册Azure账号的主邮箱...

如果删除这段代码,我会遇到更多有关未找到资源的失败,因此我相信我的 ARM 模板依赖于这段特定的 code/resource。

这里的最终目标是能够使用 ARM 模板轻松地从开发到测试到暂存到生产,并拥有来自 API 管理服务的所有内容并且它 API 完好无损并且只需更改后端 URL。我相信我快到了,只是想调试这个脚本,我们将不胜感激!

找到这个有用的资源:azure-api-management-devops-resource-kit

尝试

"scope": "[concat(resourceId('Microsoft.ApiManagement/service', parameters('service_testAPITalha_name')), '/apis')]",

我运行遇到了同样的问题,但已经解决了这个问题。 您很可能已经根据 'Export template' 函数生成了 ARM 模板?

这将生成两个 'default' 订阅和一个默认用户,即管理员。 删除所有三个,您的模板应该 运行,没有问题。 管理员的 'Starter' 和 'Unlimited' 订阅始终在没有 ARM 模板指令的情况下创建。

因此删除 Microsoft.ApiManagement/service/users 部分:

"[concat(parameters('service_testAPITalha_name'), '/1')]"

以及包含以下内容的两个订阅部分:

"ownerId": "[resourceId('Microsoft.ApiManagement/service/users', parameters('service_testAPITalha_name'), '1')]",
"scope": "[resourceId('Microsoft.ApiManagement/service/products', parameters('service_testAPITalha_name'), 'starter')]

和:

"ownerId": "[resourceId('Microsoft.ApiManagement/service/users', parameters('service_testAPITalha_name'), '1')]",
"scope": "[resourceId('Microsoft.ApiManagement/service/products', parameters('service_testAPITalha_name'), 'unlimited')]