Connect Azure Web App to vNet using ARM template

混江龙づ霸主 提交于 2019-12-05 04:58:20

I could never make that work just by the ARM template alone. However if you can spend one more PowerShell command post-creation, it works beautifully:

# Set VNET Integration for Web App

$ResourceGroup = "WeMadeThatInWestEuropeDidntWe"
$WebApp = "LearningMomentsInProduction"
$PropertiesObject = @{
       vnetName = "JimAreYouSureThisIsTheStagingVNET";
}

Set-AzureRmResource -PropertyObject $PropertiesObject `
                    -ResourceGroupName $ResourceGroup `
                    -ResourceType Microsoft.Web/sites/config `
                    -ResourceName $WebApp/web `
                    -ApiVersion 2015-08-01 -Force -Verbose |
                        Select -expand Properties |
                        Select VnetName

# Expected output:
#
#  VnetName                                   
#  --------                                   
#  JimAreYouSureThisIsTheStagingVNET
#
# At this point your Web App is hooked up to the VNET

EDIT:

This does not do what i thought it does.

To resync Point-to-site certificates:

$ResourceGroup = "WeMadeThatInWestEuropeDidntWe"
# VNET Name or Gateway name, try with gateway name!
$vnetName = "JimAreYouSureThisIsTheStagingVNET";

$PropertiesObject = @{
  resyncRequired = "true"
}

Set-AzureRmResource -PropertyObject $PropertiesObject -ResourceGroupName $ResourceGroup `
                    -ResourceType Microsoft.Web/sites/virtualNetworkConnections `
                    -ResourceName $VnetName
                    -ApiVersion 2015-08-01 `
                    -Force -Verbose

A good way of finding the correct settings after you have configured it correct in the Azure Portal, is to take a look under the hood. This can be done by taking a look through https://resources.azure.com/ or the Resource Explorer in the Azure portal.

Here you will find the json in the state it is working and compare those to your ARM template. The settings can't be copied 1-on-1, but it comes close. Good luck with finding the difference.

You put it as a nested resource within the site:

(This assumes everything is under the same subscription and resource group, else, you will need to modify the parameters for resourceId())

"properties":[],
"resources": [
                {
                    "name": "[concat(variables('webappSiteName'), '/', variables('webappSiteName'), '-vnetIntegration')]",
                    "type": "Microsoft.Web/sites/virtualNetworkConnections",
                    "apiVersion": "2018-02-01",
                    "properties": {
                        "vnetResourceId": "[resourceId('Microsoft.Network/virtualNetworks', 'vnetname')]"
                    },
                    "dependsOn": [
                        "[resourceId('Microsoft.Web/sites', variables('webappSiteName'))]"
                    ]
                }
]

At minimum, that what's required, however, the Microsoft.Web/sites/virtualNetworkConnections resource must have the client certificate data provided (which must be configured in the P2S connection in your vnet gateway), which is the property certBlob which according to the documentation it is:

A certificate file (.cer) blob containing the public key of the private key used to authenticate a Point-To-Site VPN connection.

Having that subnode worked for me, if you don't specify the certificate information, your web application(s) will show an error saying the certificates are not in sync.

Refer to the virtualNetworkConnections [documentation online](https://docs. microsoft.com/en-us/azure/templates/microsoft.web/2018-02-01/sites/virtualnetworkconnections)

Hope this helps.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!