从ARM模板获取API管理的公共IP地址

msl*_*lot 2 azure azure-api-management azure-rm-template

我得到了这个 API 管理 ARM 模板

{
      "apiVersion": "2017-03-01",
      "name": "[variables('am-apimanagement-service-name')]",
      "type": "Microsoft.ApiManagement/service",
      "location": "North Europe",
      "sku": {
        "name": "[parameters('am-sku')]",
        "capacity": "[parameters('am-skuCount')]"
      },
      "properties": {
        "publisherEmail": "[parameters('am-publisher-email-p')]",
        "publisherName": "[parameters('am-publisher-name-p')]"
      },
      "resources": [
        {
          "type": "apis",
          "apiVersion": "2017-03-01",
          "name": "test",
          "dependsOn": [
            "[concat('Microsoft.ApiManagement/service/',variables('am-apimanagement-service-name'))]"
          ],
          "properties": {
            "displayName": "test",
            "description": "",
            "serviceUrl": "[concat('https://test-',parameters('environment'),'.azurewebsites.net')]",
            "path": "test",
            "protocols": [
              "https"
            ],
            "isCurrent": true
          },
          "resources": [
            {
              "apiVersion": "2017-03-01",
              "type": "operations",
              "name": "GetTEst",
              "dependsOn": [
                "[concat('Microsoft.ApiManagement/service/', variables('am-apimanagement-service-name'), '/apis/test')]"
              ],
              "properties": {
                "displayName": "GET",
                "method": "GET",
                "urlTemplate": "/api/sites",
                "description": "Get"
              }
            }
          ]

        }
      ]
    }
Run Code Online (Sandbox Code Playgroud)

还有这个 Web API ARM 模板

   {
      "apiVersion": "2016-03-01",
      "name": "[variables('swa-name')]",
      "type": "Microsoft.Web/sites",
      "properties": {
        "name": "[variables('swa-name')]",
        "serverFarmId": "[variables('swa-hosting-plan-name')]",
        "hostingEnvironment": "[parameters('swa-hosting-environment')]",
        "siteConfig": {
          "appSettings": [
            {
              "name": "Test:ConnectionString",
              "value": "[concat('Server=tcp:', reference(resourceId('Microsoft.Sql/servers/', variables('db-serverName'))).fullyQualifiedDomainName, ',1433;Initial Catalog=', variables('db-databaseName'), ';Persist Security Info=False;User ID=', parameters('db-administratorLogin'), ';Password=', parameters('db-administratorLoginPassword'), ';MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;')]"
            }
          ],
          "ipSecurityRestrictions": [
            {
              "ipAddress": "[variables('test-ip-address')]",
              "subnetMask": "255.255.255.255"
            }
          ]
        }
      },
      "location": "[parameters('swa-location')]",
      "tags": {

      },
      "kind": "api",
      "dependsOn": [
        "[concat('Microsoft.Web/serverfarms/', variables('swa-hosting-plan-name'))]"
      ]
    }
Run Code Online (Sandbox Code Playgroud)

如何使用参考函数从 Web API 获取 API 管理资源的 IP 地址?我想将 API 管理 IP 地址放在 ipSecurityRestrictions 中。我想不通,这让我很沮丧。

我已经从 ARM 模板的 web api 资源资源部分尝试过这个:

"ipSecurityRestrictions": [
            {
              "ipAddress": "[variables('test-ip-address')]",
              "subnetMask": "255.255.255.255"
            },
            {
              "ipAddress": "[reference(variables('am-apimanagement-service-name')).publicIPAddresses[0]]",
              "subnetMask": "255.255.255.255"
            }
          ]
Run Code Online (Sandbox Code Playgroud)

但它不起作用。也许我无法在流程的这一步中获取 IP 地址?我正在阅读有关输出和链接模板的信息。也许这是解决方案?

msl*_*lot 5

这里最疯狂的是我需要两件事:

  1. apiVersion 到参考
  2. 我需要引用 staticIp 属性

问题是免费层 API 管理资源实际上没有分配静态 IP,而是动态 IP。静态 ip 地址仍然分配给引用对象的 staticIp 属性:

"ipAddress": "[reference(variables('am-apimanagement-service-name'),'2017-03-01').staticIps[0]]"
Run Code Online (Sandbox Code Playgroud)

这将正确引用 IP。