skip to Main Content

I use a bicep script to create a virtual network and 3 subnets

param vnetName string = 'vnet'

@description('The IP address range for virtual network')
param vnetAddressPrefix string = '10.201.0.0/16' //This value cannot be changed as it is used for deploying a containerApp

param subnetname string = 'subnet-app'
@description('The IP address space used for app subnet.')
param appSubnetAddressPrefix string = '10.201.0.0/23' //this subnet range cannot be changed as used for deploying containerApp

param privatesubnet string = 'subnet-pe'
@description('The IP address space used ')
param privatesubnetaddressprefix string = '10.201.1.0/23'

param assetsubnet string = 'subnnet-assets'
@description('The IP address space used for subnet asset.')
param assetsnet string = '10.201.2.0/23'

When i run the bicep file which should create 1 Virtual network and 3 subnets i get this
error.

"code": "InvalidTemplateDeployment", "message": "The template deployment 'exdeploy' is not valid according to the validation procedure. The tracking id is 'adfd-1e75eedfd40fa-32343-dderese1232'. See inner errors for details."}

Inner Errors: 
{"code": "InvalidCIDRNotation", "target": "/subscriptions/dysd/resourceGroups/mygrp/providers/Microsoft.Network/virtualNetworks/vnet-edersede", "message": "The address prefix 10.201.1.0/23 in resource /subscriptions/dysd/resourceGroups/mygrp/providers/Microsoft.Network/virtualNetworks/vnet-edersede/subnets/subnet-pe has an invalid CIDR notation. For the given prefix length, the address prefix should be 10.201.0.0/23."}

No resource gets created
Can anyone help here? Thanks

2

Answers


  1. I created Bicep file in My Local and the below code is filled in this file.

    param location string = resourceGroup().location
    resource vnet 'Microsoft.Network/virtualNetworks@2021-08-01' = {
      name: 'devvnet'
      location: resourceGroup().location
      properties: {
        addressSpace: {
          addressPrefixes: [
            '10.0.0.0/16'
          ]
        }
      }
    }
    resource subnet1 'Microsoft.Network/virtualNetworks/subnets@2021-08-01' = {
      parent: vnet
      name: 'subnet1'
      properties: {
        addressPrefix: '10.0.4.0/23'
        networkSecurityGroup: {
          id: nsg1.id
        }
      }
    }
    
    resource nsg1 'Microsoft.Network/networkSecurityGroups@2021-08-01' = {
      location: location
      name: 'nsg1'
    }
    
    
    • The above code ran successfully. check the below image.
      enter image description here

    Result :
    enter image description here

    Login or Signup to reply.
  2. Use any CIDR calculator(example).

    10.201.0.0/23 has a starting IP of 10.201.0.0 and ending IP of 10.201.1.255. So your subnet 2 of 10.201.1.0/23 is actually overlapping subnet 1.

    You can configure the following non-overlapping CIDRs for your subnets. This will work.

    Subnet 1 : 10.201.0.0/23

    Subnet 2 : 10.201.2.0/23

    Subnet 3 : 10.201.4.0/23

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search