Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save maskati/590b5dd7d97b6ec4dd03e143f995063b to your computer and use it in GitHub Desktop.
Save maskati/590b5dd7d97b6ec4dd03e143f995063b to your computer and use it in GitHub Desktop.
Azure resource naming abbreviations, rules and restrictions

Microsoft documents recommended abbreviations for Azure resource types as well as resource type specific naming rules and restrictions. Microsoft also publishes the Azure Naming Tool which happens to contain a structured repository of Azure resource type abbreviations and naming rules.

You can get a quick searchable grid of this data using PowerShell. If you prefer you can replace the Windows-only Out-GridView with the cross platform Out-ConsoleGridView.

(irm https://raw.githubusercontent.com/mspnp/AzureNamingTool/main/src/repository/resourcetypes.json) `
|select resource,property,shortname,scope,lengthmin,lengthmax,validtext,invalidtext,invalidcharacters,regx `
|ogv -t 'Azure resource naming abbreviations, rules and restrictions'

image

Alternatively you can transform the source into a Json object indexed by resource type:

(irm https://raw.githubusercontent.com/mspnp/AzureNamingTool/main/src/repository/resourcetypes.json) `
|%{$x=[pscustomobject]::new()}{$x|add-member -notepropertyname "$($_.resource)$($_.property?" ($($_.property))":'')" -notepropertyvalue $_.shortname}{$x} `
|convertto-json|out-file resourcetypes.json

Which you can consume in your Bicep files: image

Warning

Doing this increases your final compiled template size somewhat.

@ikkentim
Copy link

ikkentim commented Apr 4, 2025

The second command didn't work for me (ps error'd on the $_.property?"... expression)

I've rewritten it a bit to make it work on my machine

$resourceTypes = Invoke-RestMethod https://raw.githubusercontent.com/mspnp/AzureNamingTool/main/src/repository/resourcetypes.json

$result = @{}

$resourceTypes | ForEach-Object {
    $propertyName = if ($_.property) {
        "$($_.resource) ($($_.property))"
    } else {
        "$($_.resource)"
    }
    $result[$propertyName] = $_.shortname
}

$result | ConvertTo-Json | Out-File resourcetypes.json

@maskati
Copy link
Author

maskati commented Apr 9, 2025

@ikkentim this is possibly a PowerShell version issue. The ternary operator requires PowerShell 7.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment