ARM模板 - 为Web App创建SQL Server防火墙规则

时间:2017-06-21 00:19:21

标签: azure-resource-manager

我创建了SQL Server和数据库,Web App,发布的网站和数据库,并进入网站的登录屏幕。

当我登录时,我收到500个包含当前不允许访问新创建的SQL Server的Web应用程序的IP地址。

我非常希望收集分配的IP地址(怀疑它是AZURE内部IP地址),以便在模板中创建防火墙规则。

我成功地为存储帐户密钥和数据库连接字符串添加应用设置。这些都很好用。

无法找到对网站内部IP的任何引用,这非常令人沮丧。我在天蓝色的门户网站上尝试过对象浏览器。

建议赞赏! 安迪

1 个答案:

答案 0 :(得分:1)

如果您使用的是Azure SQL,有关如何设置Azure数据库防火墙的信息,请参阅document

  

无法找到对网站内部IP的任何引用非常令人沮丧?

如果要让Azure服务访问Azure SQL数据库,我们只需要设置

允许访问Azure服务。默认值为

enter image description here

我们也可以获取出站IP,我们可以从azure资源(https://resources.azure.com/)获取它们,然后将outboundIpAddresses添加到Azure SQL防火墙规则允许的IP列表中。

enter image description here

注意:对于Azure WebApp,outboundIpAddresses不是静态ips,当我们重新启动WebApp或更改WebApp服务计划时,它们可能会更改。

如果我们想通过ARM模板添加防火墙规则,我们可以使用以下演示代码:

{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
      "testfirewallAdminLogin": {
          "type": "string",
          "minLength": 1
      },
      "testfirewallAdminLoginPassword": {
          "type": "securestring"
      }},
  "variables": {
      "testfirewallName": "[concat('testfirewall', uniqueString(resourceGroup().id))]"},
  "resources": [
      {
          "name": "[variables('testfirewallName')]",
          "type": "Microsoft.Sql/servers",
          "location": "[resourceGroup().location]",
          "apiVersion": "2014-04-01-preview",
          "dependsOn": [ ],
          "tags": {
              "displayName": "testfirewall"
          },
          "properties": {
              "administratorLogin": "[parameters('testfirewallAdminLogin')]",
              "administratorLoginPassword": "[parameters('testfirewallAdminLoginPassword')]"
          },
          "resources": [
              {
                  "name": "AllowAllWindowsAzureIps",
                  "type": "firewallrules",
                  "location": "[resourceGroup().location]",
                  "apiVersion": "2014-04-01-preview",
                  "dependsOn": [
                      "[resourceId('Microsoft.Sql/servers', variables('testfirewallName'))]"
                  ],
                "properties": {
                  "startIpAddress": "x.x.x.x",
                  "endIpAddress": "x.x.x.x"
                }
              }
          ]
      }],
  "outputs": {

  }
}