Use valid Cosmos DB account names#
Operational Excellence · Cosmos DB · Rule · 2021_09 · Awareness
Cosmos DB account names should meet naming requirements.
Description#
When naming Azure resources, resource names must meet service requirements. The requirements for Cosmos DB account names are:
- Between 3 and 44 characters long.
- Lowercase letters, numbers, and hyphens.
- Start and end with letters and numbers.
- Cosmos DB account names must be globally unique.
Recommendation#
Consider using names that meet Cosmos DB account naming requirements. Additionally consider naming resources with a standard naming convention.
Examples#
Configure with Bicep#
To deploy accounts that pass this rule:
- Set the
nameproperty to a string that matches the naming requirements. - Optionally, consider constraining name parameters with
minLengthandmaxLengthattributes.
For example:
@minLength(3)
@maxLength(44)
@description('The name of the resource.')
param name string
@description('The location resources will be deployed.')
param location string = resourceGroup().location
resource account 'Microsoft.DocumentDB/databaseAccounts@2025-04-15' = {
name: name
location: location
properties: {
enableFreeTier: false
consistencyPolicy: {
defaultConsistencyLevel: 'Session'
}
databaseAccountOfferType: 'Standard'
locations: [
{
locationName: location
failoverPriority: 0
isZoneRedundant: true
}
]
disableKeyBasedMetadataWriteAccess: true
minimalTlsVersion: 'Tls12'
}
}
Configure with Azure Verified Modules
A pre-validated module supported by Microsoft is available from the Azure Bicep public registry. To reference the module, please use the following syntax:
To use the latest version:
Configure with Azure template#
To deploy accounts that pass this rule:
- Set the
nameproperty to a string that matches the naming requirements. - Optionally, consider constraining name parameters with
minLengthandmaxLengthattributes.
For example:
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"name": {
"type": "string",
"minLength": 3,
"maxLength": 44,
"metadata": {
"description": "The name of the resource."
}
}
},
"resources": [
{
"type": "Microsoft.DocumentDB/databaseAccounts",
"apiVersion": "2025-04-15",
"name": "[parameters('name')]",
"location": "[parameters('location')]",
"properties": {
"enableFreeTier": false,
"consistencyPolicy": {
"defaultConsistencyLevel": "Session"
},
"databaseAccountOfferType": "Standard",
"locations": [
{
"locationName": "[parameters('location')]",
"failoverPriority": 0,
"isZoneRedundant": true
}
],
"disableKeyBasedMetadataWriteAccess": true,
"minimalTlsVersion": "Tls12"
}
}
]
}
Notes#
This rule does not check if Cosmos DB account names are unique.
Links#
- OE:04 Continuous integration
- Operational Excellence: Level 2
- Naming rules and restrictions for Azure resources
- Recommended abbreviations for Azure resource types
- Parameters in Bicep
- Bicep functions
- Azure deployment reference