如何使用 Azure ARM 模板在 Azure SQL Server 中一次添加多个客户端 IP 地址?

Pra*_*eep 3 azure azure-sql-database azure-rm-template

目前,我正在努力通过使用 Azure ARM 模板在防火墙规则下添加多个 IP 地址来部署 Azure SQL 数据库。

这是在 Azure SQL Server 的防火墙设置下添加一个 IP 地址的代码。

{
      "name": "AllowAllMicrosoftAzureIps",
      "type": "firewallrules",
      "apiVersion": "2014-04-01",
      "location": "[resourceGroup().location]",
      "properties": {
        "startIpAddress": "[parameters('startIpAddress')]",
        "endIpAddress": "[parameters('endIpAddress')]"
      },
      "dependsOn": [
        "[variables('sqlServerName')]"
      ]
    },
Run Code Online (Sandbox Code Playgroud)

但我想使用 Azure ARM 模板在 Azure SQL 数据库的防火墙设置下一次添加多个 IP 地址。

Dan*_*son 5

我还没有测试过,但我相信它看起来像这样。使用copy迭代器并提供起始和结束 IP 地址的数组。

"parameters": { 
    "firewallIpAddresses": { 
        "type": "object", 
        "defaultValue": [ 
            { "start": "1.1.1.0", "end": "1.1.1.10","clientName": "Client1" },
            { "start": "1.2.3.4", "end": "1.2.3.16","clientName": "Client2" },
            { "start": "1.2.0.1", "end": "1.2.0.20","clientName": "Client3" }
        ] 
    }
},
"resources": [
{
     "name": "[concat(variables('sqlServerName'), '/', parameters('firewallIpAddresses')[copyIndex()].clientName)]",
     "type": "Microsoft.Sql/servers/firewallrules",
     "apiVersion": "2014-04-01",
     "location": "[resourceGroup().location]",
     "properties": {
        "startIpAddress": "[parameters('firewallIpAddresses')[copyIndex('firewallrulecopy')].start]",
        "endIpAddress": "[parameters('firewallIpAddresses')[copyIndex('firewallrulecopy')].end]"
     },
     "dependsOn": [
        "[variables('sqlServerName')]"
    ],
    "copy": {
        "name": "firewallrulecopy",
        "count": "[length(parameters('firewallIpAddresses'))]"
    }
}
]
Run Code Online (Sandbox Code Playgroud)