I’m getting an error "Cannot find VirtualNetwork with name vnet-name". The vnet is in a different resource group than the web app.
var subnetName = 'subnetName'
var linuxVersion = 'node|20-lts'
resource appService 'Microsoft.Web/sites@2023-12-01' = {
name: '${webAppPrefix}${name}'
location: location
properties: {
serverFarmId: webAppPlan.id
publicNetworkAccess: 'Disabled'
virtualNetworkSubnetId: resourceId('Microsoft.Network/virtualNetworks/subnets', 'vnet-name' , subnetName)
siteConfig: {
linuxFxVersion: linuxVersion
}
}
}
2
Answers
Because the Virtual Network is in a different Resource Group as the app service, the Resource Group must be explicitly specified as follows:
it is well documented here: https://learn.microsoft.com/en-us/azure/azure-resource-manager/templates/template-functions-resource
Because the existing virtual network is in a different resource group, you need to pass the name of the resource group that it is in to the
resourceId
function.Alternatively, use the
existing
keyword to work with your existing resources.