'How to add multiple client IP addresses at time in Azure SQL Server using Azure ARM Templates?
Currently I am working on to deploy the Azure SQL Database by adding multiple IP addresses under Firewall rules using Azure ARM templates.
This is the code for adding one IP address under Firewall settings of Azure SQL Server.
{
"name": "AllowAllMicrosoftAzureIps",
"type": "firewallrules",
"apiVersion": "2014-04-01",
"location": "[resourceGroup().location]",
"properties": {
"startIpAddress": "[parameters('startIpAddress')]",
"endIpAddress": "[parameters('endIpAddress')]"
},
"dependsOn": [
"[variables('sqlServerName')]"
]
},
But I want to add the multiple IP addresses at a time under Firewall settings of Azure SQL Database using Azure ARM templates.
Solution 1:[1]
I haven't tested it, but I believe it would look something like this. Use the copy
iterator and supply an array of start and end IP addresses.
"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'))]"
}
}
]
Solution 2:[2]
"name": "nba-instance-one",
"type": "Microsoft.Sql/servers",
"apiVersion": "2014-04-01",
"location": "[resourceGroup().location]",
"tags": {
"displayName": "sql-server-instance"
},
"properties": {
"administratorLogin": "admin",
"administratorLoginPassword": "password"
},
"resources": [
{
"type": "firewallRules",
"apiVersion": "2014-04-01",
"location": "[resourceGroup().location]",
"name": "LaptopIp",
"properties": {
"startIpAddress": "39.188.172.29",
"endIpAddress": "39.188.172.29"
},
"dependsOn": [
"[resourceId('Microsoft.Sql/servers', 'sql-server-instance')]"
]
},
{
"type": "firewallRules",
"apiVersion": "2014-04-01",
"location": "[resourceGroup().location]",
"name": "OtherIP",
"properties": {
"startIpAddress": "38.171.192.48",
"endIpAddress": "38.171.192.48"
},
"dependsOn": [
"[resourceId('Microsoft.Sql/servers', 'sql-server-instance')]"
]
}
If it's only a few IP addresses you could add more fire wall rules for each IP address.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Pradeep |
Solution 2 | Daniel Albert |