I'm trying to manage my Azure resources with bicep. The resource group that I currently deploy in has also some externally managed resources including a vnet (managed externally, so marking it es existing in my bicep template).
I need my azure Function app that I deploy using bicep to have that existing vnet (managed externally) to be injected for the outbound traffic. I know how to do it in the Azure UI when you create a Function app: you need to select "Enable network injection" to "On" and then select your subnet from the dropdown. Then it would look like this in the UI
This is the expected result. But I can't do it in bicep. Tried the following:
Option 1:
resource azFunction 'Microsoft.Web/sites@2023-01-01' = {
name: name
.....
properties: {
enabled: true
serverFarmId: appServicePlan.id
reserved: true
publicNetworkAccess: 'Disabled'
virtualNetworkSubnetId: vNet.id
Option 2:
resource azFunction 'Microsoft.Web/sites@2023-01-01' = {
name: name
.....
properties: {
enabled: true
serverFarmId: appServicePlan.id
reserved: true
publicNetworkAccess: 'Disabled'
virtualNetworkSubnetId: vNet.properties.subnets[0].id
(so trying both vnet itself and the only subnet of this vnet)
Option 3:
resource azFunctionVnetConnection 'Microsoft.Web/sites/virtualNetworkConnections@2023-01-01' = {
parent: azFunction
name: 'vnetconnection'
properties: {
vnetResourceId: vNet.id
isSwift: false
}
}
Option 4:
resource azFunctionVnetConnection 'Microsoft.Web/sites/virtualNetworkConnections@2023-01-01' = {
parent: azFunction
name: 'vnetconnection'
properties: {
vnetResourceId: vNet.properties.subnets[0].id
isSwift: false
}
}
also both vnet and its only subnet. Still seeing something like this:
So the question is: how do I do in bicep the Virtual Network integration as it's done from the UI?
UPDATE: I already have the delegations in my subnet to serverFarms, I forgot to specify this in my initial question. That's in regards to @wenbo's response. The whole vnet/subnet resource looks like:
resource vNet 'Microsoft.Network/virtualNetworks@2023-06-01' = {
name: vnetName
location: location
properties: {
addressSpace: {
addressPrefixes: [
'172.22.0.0/24'
]
}
subnets: [
{
name: 'default'
properties: {
addressPrefix: '172.22.0.0/24'
networkSecurityGroup: {
id: nsg.id
}
serviceEndpoints: [
{
service: 'Microsoft.EventHub'
locations: ['*']
}
{
service: 'Microsoft.AzureCosmosDB'
locations: ['*']
}
{
service: 'Microsoft.Storage'
locations: ['westus', 'eastus']
}
{
service: 'Microsoft.Web'
locations: ['*']
}
{
service: 'Microsoft.Sql'
locations: ['westus']
}
{
service: 'Microsoft.KeyVault'
locations: ['*']
}
{
service: 'Microsoft.ContainerRegistry'
locations: ['*']
}
{
service: 'Microsoft.AzureActiveDirectory'
locations: ['*']
}
{
service: 'Microsoft.ServiceBus'
locations: ['*']
}
]
delegations: [
{
name: 'funcwebapp'
properties: {
serviceName: 'Microsoft.Web/serverFarms'
}
type: 'Microsoft.Network/virtualNetworks/subnets/delegations'
}
]
privateEndpointNetworkPolicies: 'Enabled'
privateLinkServiceNetworkPolicies: 'Enabled'
}
}




afaik, this should do the trick: