Virtual Network Subnet name must be valid#
Operational Excellence · Virtual Network · Rule · 2020_06 · Awareness
Azure Resource Manager (ARM) has requirements for Virtual Network Subnet names.
Description#
When naming Azure resources, resource names must meet service requirements. The requirements for Route table names are:
- Between 1 and 80 characters long.
- Alphanumerics, underscores, periods, and hyphens.
- Start with alphanumeric.
- End alphanumeric or underscore.
- Subnet names must be unique within a virtual network.
Recommendation#
Consider using names that meet subnet naming requirements. Additionally consider naming resources with a standard naming convention.
Examples#
Configure with Bicep#
To deploy virtual network subnets that pass this rule:
- Set the
name
property to a string that matches the naming requirements. - Optionally, consider constraining name parameters with
minLength
andmaxLength
attributes.
For example:
Azure Bicep snippet
@minLength(1)
@maxLength(80)
@description('The name of the resource.')
param name string
resource subnet 'Microsoft.Network/virtualNetworks/subnets@2024-05-01' = {
parent: vnet
name: name
properties: {
addressPrefix: '10.0.0.0/24'
networkSecurityGroup: {
id: nsg.id
}
defaultOutboundAccess: false
}
}
Configure with Azure template#
To deploy virtual network subnets that pass this rule:
- Set the
name
property to a string that matches the naming requirements. - Optionally, consider constraining name parameters with
minLength
andmaxLength
attributes.
For example:
Azure Template snippet
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"metadata": {
"_generator": {
"name": "bicep",
"version": "0.34.44.8038",
"templateHash": "1920943566989111543"
}
},
"parameters": {
"name": {
"type": "string",
"minLength": 1,
"maxLength": 80,
"metadata": {
"description": "The name of the resource."
}
}
},
"resources": [
{
"type": "Microsoft.Network/virtualNetworks/subnets",
"apiVersion": "2024-05-01",
"name": "[format('{0}/{1}', parameters('name'), parameters('name'))]",
"properties": {
"addressPrefix": "10.0.0.0/24",
"networkSecurityGroup": {
"id": "[resourceId('Microsoft.Network/networkSecurityGroups', parameters('name'))]"
},
"defaultOutboundAccess": false
},
"dependsOn": [
"[resourceId('Microsoft.Network/networkSecurityGroups', parameters('name'))]",
"[resourceId('Microsoft.Network/virtualNetworks', parameters('name'))]"
]
}
]
}
Notes#
This rule does not check if subnet names are unique.
Links#
- OE:04 Continuous integration
- Naming rules and restrictions for Azure resources
- Recommended abbreviations for Azure resource types
- Parameters in Bicep
- Bicep functions
- Azure deployment reference - Virtual Network
- Azure deployment reference - Subnet