Cloud can be tricky sometimes. Find out what scenarios we've ran into that are worth being mentioned and explained.
Subnetting is an essential part of Azure networking, ensuring efficient IP allocation and network segmentation. With Bicep CIDR functions, subnetting can now be done programmatically, simplifying the process of defining and managing IP address ranges within Azure Virtual Networks (VNets).
output outCidrDetails object = parseCidr('10.50.0.0/24')
{
"broadcast": "10.50.0.255",
"cidr": 24,
"firstUsable": "10.50.0.1",
"lastUsable": "10.50.0.254",
"netmask": "255.255.255.0",
"network": "10.50.0.0"
}
output outSubnet1 string = cidrSubnet('10.50.0.0/24', 26, 0) // First /26 subnet
output outSubnet2 string = cidrSubnet('10.50.0.0/24', 26, 1) // Second /26 subnet
{
"outSubnet1": "10.50.0.0/26",
"outSubnet2": "10.50.0.64/26"
}
output outHostIps array = [for i in range(0, 5): cidrHost('10.50.0.0/26', i)]
{
"outHostIps": [
"10.50.0.1",
"10.50.0.2",
"10.50.0.3",
"10.50.0.4",
"10.50.0.5"
]
}
@description('The primary IP address space for the virtual network. Default: 10.50.0.0/24')
param parAddressSpace string = '10.50.0.0/24'
@description('The CIDR prefix for subnets. Default: /26')
param parSubnetCidr int = 26
@description('The number of subnets to create. Default: 4')
param parSubnetCount int = 4
var varSubnets = [for i in range(0, parSubnetCount): {
name: 'subnet-${i}'
properties: {
addressPrefix: cidrSubnet(parAddressSpace, parSubnetCidr, i)
}
}]
resource resVirtualNetwork 'Microsoft.Network/virtualNetworks@2023-05-01' = {
name: 'my-vnet'
location: 'eastus'
properties: {
addressSpace: {
addressPrefixes: [parAddressSpace]
}
subnets: varSubnets
}
}
output outSubnets array = varSubnets
Explanation of the Deployment
[
{ "name": "subnet-0", "properties": { "addressPrefix": "10.50.0.0/26" } },
{ "name": "subnet-1", "properties": { "addressPrefix": "10.50.0.64/26" } },
{ "name": "subnet-2", "properties": { "addressPrefix": "10.50.0.128/26" } },
{ "name": "subnet-3", "properties": { "addressPrefix": "10.50.0.192/26" } }
]
az deployment group create --resource-group myResourceGroup --template-file ./subnetting.bicep
This will create: