配置FirewallRules在ARM模板所有PossibleOutboundIpAddresses

问题描述 投票:2回答:1

我想创建防火墙规则,只有我Azure的Web应用程序可以连接到我的数据库。如果可能的话,我想这样做在我的ARM模板。这是我迄今为止尝试:

{
  "variables": {
    "defaultResourceName": "[resourceGroup().name]",
  },
  "resources": [
    {
      "type": "Microsoft.Web/sites/firewallRules",
      "name": "[concat('AllowAzureIpAddress', copyIndex()",
      "apiVersion": "2015-05-01-preview",
      "properties": {
        "startIpAddress": "[reference('Microsoft.Web/sites', variables('defaultResourceName')).possibleOutboundIpAddresses[copyIndex()]]",
        "endIpAddress": "[reference('Microsoft.Web/sites', variables('defaultResourceName')).possibleOutboundIpAddresses[copyIndex()]]"
      },
      "dependsOn": [
        "[resourceId('Microsoft.Sql/servers/', toLower(variables('defaultResourceName')))]"
      ],
      "copy": {
        "name": "firewallRuleCopy",
        "count": "[length(reference('Microsoft.Web/sites', variables('defaultResourceName')).possibleOutboundIpAddresses)]"
      }
    },
  ]
}

主要的问题是获得PossibleOutboundIpAddresses。我不知道如果他们提供给我在这里,当我尝试验证我的ARM模板,上面写着The template function 'reference' is not expected at this location. Please see https://aka.ms/arm-template-expressions for usage details..我得到一个错误

有没有人这样做是对如何去得到那些OutboundIpAddresses(最好是在一个列表中,这样的副本可以使用它们)有什么建议?

azure arm-template azure-template
1个回答
2
投票

你的问题不是来自于一个错误的方式使用的参考作用,但事实上,你不能(在运行时副本在“编译时”进行评估,而参考,所以无法评估副本的长度)的拷贝属性中使用的参考作用。你可能的解决办法是:嵌套的部署。这里是我一直使用的是什么:

{
    "name": "firewallRules",
    "type": "Microsoft.Resources/deployments",
    "apiVersion": "2015-01-01",
    "properties": {
        "mode": "Incremental",
        "templateLink": {
            "uri": "https://paste.ee/d/Hkebg/0",
            "contentVersion": "1.0.0.0"
        },
        "parameters": {
            "prefix": {
                "value": "[variables('prefix')]"
            },
            "iterator": {
                "value": "[split(reference(concat(parameters('prefix'), '-', parameters('webAppNames').name), '2016-03-01', 'Full').properties.possibleOutboundIpAddresses, ',')]"
            }
        }
    }
},
© www.soinside.com 2019 - 2024. All rights reserved.