Virtual network bicep script unable to add subnet delegation for services

MrFlinstone 686 Reputation points
2023-06-26T12:42:55.0066667+00:00

I have got the code base which can be found on https://github.com/jake7745/bicep-vnet with the initial work by github@ChristopherGLewis.

The code works well by creating a virtual network, and subnets the difficulty here is that one cannot add service delegation to the subnets.

param vNetName string
param rgVnet string
param subnetName string
param subnetAddressPrefix string
param delegations array = []

//Subnet with delegation
resource subnet 'Microsoft.Network/virtualNetworks/subnets@2020-06-01' = {
  name: '${vNetName}/${subnetName}'
  properties: { 
    // delegations: delegations
    delegations:[
      {
        name: 'delegation'
        properties:{
          serviceName: 'Microsoft.Web/serverfarms'
        }
      }
    ]
  }
}

The code above is how a service delegation will be added, however I just cannot get it to work. The vnet and subnets are created, but without the delegation.

Any help or insight here would be appreciated.

Azure Virtual Network
Azure Virtual Network
An Azure networking service that is used to provision private networks and optionally to connect to on-premises datacenters.
2,762 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. AirGordon 7,150 Reputation points
    2023-06-26T13:09:54.3666667+00:00

    Try setting the delegation name differently.

    This code works;

    param location string = resourceGroup().location
    param vNetName string = 'vnetGord'
    param vNetAddressPrefix string = '10.0.0.0/16'
    param subnetAddressPrefix string= '10.0.1.0/24'
    
    resource vnet 'Microsoft.Network/virtualNetworks@2022-11-01' = {
      name: vNetName
      location: location
      properties: {
        addressSpace: {
          addressPrefixes: [vNetAddressPrefix]
        }
      }
    }
    
    resource serverFarmSubnet 'Microsoft.Network/virtualNetworks/subnets@2020-06-01' = {
      name: 'aSubnet'
      parent: vnet
      properties: { 
        addressPrefix: subnetAddressPrefix
        delegations: [
          {
            name: 'Microsoft.Web/serverfarms'
            properties: {
              serviceName: 'Microsoft.Web/serverfarms'
            }
          }
        ]
      }
    }
    
    
    
    1 person found this answer helpful.

  2. Stanislav Zhelyazkov 28,186 Reputation points MVP Volunteer Moderator
    2023-06-26T12:53:45.9666667+00:00

    Hi,

    There is one particular issue with this resource - subnets. They should be created within Microsoft.Network/virtualNetworks resource rather as separate resource as Microsoft.Network/virtualNetworks/subnets. There is quite a big discussion here. You can check examples on how to deploy the subnet with the virtual network resource here

    Please "Accept the answer" if the information helped you. This will help us and others in the community as well.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.