用于使用新的VNet集成功能配置App Services的ARM模板?

时间:2019-02-05 12:54:48

标签: azure azure-web-app-service azure-virtual-network arm-template

我正在研究ARM模板,我已经使用两个或多个Azure应用程序服务以及应用程序服务计划创建了模板文件,然后使用每个应用程序服务的VNET Integration进行了配置。

这是示例JSON代码:

    {
  "comments": "Web-App-01",
  "name": "[variables('app_name_01')]",
  "type": "Microsoft.Web/sites",
  "location": "[variables('location')]",
  "apiVersion": "2016-08-01",
  "dependsOn": [
    "[resourceId('Microsoft.Web/serverfarms', variables('asp_name_01'))]"
  ],
  "tags": {
    "displayName": "[variables('app_name_01')]"
  },
  "properties": {
    "name": "[variables('app_name_01')]",
    "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', variables('asp_name_01'))]",
    "siteConfig": {
      "alwaysOn": true
    }
  },
    "resources": [
      {
        "type": "Microsoft.Web/sites/virtualNetworkConnections",
        "name": "[concat(variables('app_name_01'), '/', variables('vnet_connection_name'),uniqueString('asdsdaxsdsd'))]",
        "apiVersion": "2016-08-01",
        "location": "[variables('location')]",
        "properties": {
          "vnetResourceId": "[resourceId('Microsoft.Network/virtualNetworks/subnets', variables('vm_vnet_name'), variables('web_subnet_name'))]"
        },
        "dependsOn": [
          "[resourceId('Microsoft.Web/sites', variables('app_name_01'))]",
          "[resourceId('Microsoft.Network/virtualNetworks/subnets', variables('vm_vnet_name'), variables('web_subnet_name'))]"
        ]
      }
    ]
},
{
  "comments": "Web-App-02",
  "name": "[variables('app_name_02')]",
  "type": "Microsoft.Web/sites",
  "location": "[variables('location')]",
  "apiVersion": "2016-08-01",
  "dependsOn": [
    "[resourceId('Microsoft.Web/serverfarms', variables('asp_name_02'))]"
  ],
  "tags": {
    "displayName": "[variables('app_name_02')]"
  },
  "properties": {
    "name": "[variables('app_name_02')]",
    "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', variables('asp_name_01'))]",
    "siteConfig": {
      "alwaysOn": true
    }
  },
    "resources": [
      {
        "type": "Microsoft.Web/sites/virtualNetworkConnections",
        "name": "[concat(variables('app_name_02'), '/', variables('vnet_connection_name'),uniqueString('asdsdaxsdsd'))]",
        "apiVersion": "2016-08-01",
        "location": "[variables('location')]",
        "properties": {
          "vnetResourceId": "[resourceId('Microsoft.Network/virtualNetworks/subnets', variables('vm_vnet_name'), variables('web_subnet_name'))]"
        },
        "dependsOn": [
          "[resourceId('Microsoft.Web/sites', variables('app_name_02'))]",
          "[resourceId('Microsoft.Network/virtualNetworks/subnets', variables('vm_vnet_name'), variables('web_subnet_name'))]"
        ]
      }
    ]
}

上面的代码对于一些蔚蓝的应用程序服务很好,但是对于其余的应用程序服务,我在Azure应用程序服务的VNET集成期间遇到内部服务器错误或冲突或错误请求。

  

注意:当我部署上述JSON代码时,旧的VNET   配置了集成,而不是配置了新的VNET(预览)功能。因此,我需要为每个应用程序服务配置新的VNET(预览)功能。

所以,有人可以建议我如何解决上述问题。

4 个答案:

答案 0 :(得分:3)

我已经与Microsoft的Prem工程师进行了交谈。

关键是替换自动化模板

    {
        "type": "Microsoft.Web/sites/virtualNetworkConnections",
        "apiVersion": "2018-11-01",
        "name": "[concat(parameters('sites_FelixOFA_name'), '/xxxxxxx_Functions')]",
        "location": "West Europe",
        "dependsOn": [
            "[resourceId('Microsoft.Web/sites', parameters('sites_FelixOFA_name'))]"
        ],
        "properties": {
            "vnetResourceId": "[concat(parameters('virtualNetworks_FelixODevPremNet_externalid'), '/subnets/Functions')]",
            "isSwift": true
        }
    }

使用

{
  "type": "Microsoft.Web/sites/networkConfig",
  "name": "[concat(parameters('webAppName'),'/VirtualNetwork')]",
  "apiVersion": "2016-08-01",
  "properties":
              {
                            "subnetResourceId": "[parameters('subnetResourceId')]"
              }
}

其中subnetResourceId是其子网的资源ID –应该看起来像/subscriptions/{sub}/resourceGroups/{rg}/providers/Microsoft.Network/virtualNetworks/{vnetName}/subnets/{subnetName}

答案 1 :(得分:1)

我试图通过 Bicep 文件达到相同的功能,最后使用

virtualNetworkSubnetId:

为我工作。 例如:

resource webAppName_resource 'Microsoft.Web/sites@2020-12-01' =  {
  name: '${webAppName}'
  location: location
  properties: {
    serverFarmId: appServicePlanPortalName.id
    virtualNetworkSubnetId: '${vnetDeploy_module.outputs.vnetid}/subnets/${vnetDeploy_module.outputs.subnetname}'
    siteConfig: {
      linuxFxVersion: linuxFxVersion
      minTlsVersion: minTlsVersion
      http20Enabled: http20Enabled
    }
    httpsOnly: httpsOnly
  }
}

查看 https://github.com/Azure/azure-quickstart-templates/tree/master/quickstarts/microsoft.web/app-service-regional-vnet-integration 中的模板。

ARM 中的结果是:

{
  "type": "Microsoft.Web/sites",
  "apiVersion": "2021-01-01",
  "name": "[parameters('appName')]",
  "location": "[parameters('location')]",
  "kind": "app",
  "properties": {
    "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', variables('appServicePlanName'))]",
    "virtualNetworkSubnetId": "[reference(resourceId('Microsoft.Network/virtualNetworks', variables('vnetName'))).subnets[0].id]",
    "httpsOnly": true,
    "siteConfig": {
      "vnetRouteAllEnabled": true,
      "http20Enabled": true
    }
  },
  "dependsOn": [
    "[resourceId('Microsoft.Web/serverfarms', variables('appServicePlanName'))]",
    "[resourceId('Microsoft.Network/virtualNetworks', variables('vnetName'))]"
  ]
}

答案 2 :(得分:0)

我在Azure Docs GitHub帖子上找到了一个可行的示例:

How do we integrate the new vnet integrartion with ARM templates?

似乎与新的VNet集成工作方式不同,该集成使用名为Microsoft.Web/sites/config的{​​{1}}子资源而不是virtualNetwork子资源

以及需要在目标子网/ vnet上设置的一些要求(在链接中描述)。集成件看起来像这样:

Microsoft.Web/sites/virtualNetworkConnections

除此以外,除了在定义了 { "apiVersion": "2018-02-01", "type": "Microsoft.Web/sites", "name": "[parameters('appName')]", "location": "[resourceGroup().location]", ... "resources": [ { "name": "virtualNetwork", "type": "config", "apiVersion": "2018-02-01", "location": "[resourceGroup().location]", "properties": { "subnetResourceid": "[parameters('subnetResourceId')]", "swiftSupported": true }, "dependsOn": [ "[resourceId('Microsoft.Web/sites', parameters('appName'))]" ] } ] }, 端点的azure-rest-api-specs中对它的引用之外,我没有发现其他文献记录。

azure-rest-api-specs / WebApps.json

似乎(按照规范建议)用"/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Web/sites/{name}/networkConfig/virtualNetwork"代替"type": "config"也可以。

答案 3 :(得分:0)

要解决此问题,我只是将isSwiftswiftSupported选项更改为false