Home

Awesome

☁️✍️ Azure Naming

build nuget

This is a dotnet tool helping you to name Azure Resources.

It is a fork of:

The original, online version of this tool:

This tool is based on Klabbet naming convention:

It uses the abbreviations of Azure resources recommended by Microsoft:

Installation

Install:

dotnet tool install -g dotnet-azure-naming

Update:

dotnet tool update -g dotnet-azure-naming

Uninstall:

dotnet tool uninstall -g dotnet-azure-naming

Usage

Without arguments / Interactive:

azure-naming

Interactive / Without arguments

With arguments:

azure-naming --resource-type "Function app" --project-name Titanic --component-name Web --environment Development

Short:

azure-naming -r func -p Titanic -c Web -e dev

With arguments

Format as JSON:

azure-naming -r func -p Titanic -c Web -e dev -f json

Format as JSON

PowerShell:

$result = (azure-naming -r func -p Titanic -c Web -e dev -f json | ConvertFrom-Json)

PowerShell

Help:

azure-naming --help

Help

Arguments:

Azure CLI

Use azure-naming together with Azure CLI to create a web app and deploy code from GitHub:

# Get the resource name
$result = (azure-naming -r app -p Titanic$(Get-Random) -c Web -e dev -f json | ConvertFrom-Json)

# Replace the following URL with a public GitHub repo URL
$gitrepo = "https://github.com/Azure-Samples/app-service-web-dotnet-get-started.git"

# Create a resource group
az group create --location westeurope --name $result.ResourceGroup

# Create an App Service plan in FREE tier
az appservice plan create --name $result.ResourceName --resource-group $result.ResourceGroup --sku FREE

# Create a web app
az webapp create --name $result.ResourceName --resource-group $result.ResourceGroup --plan $result.ResourceName

# Deploy code from a public GitHub repository
az webapp deployment source config --name $result.ResourceName --resource-group $result.ResourceGroup --repo-url $gitrepo --branch master --manual-integration

# Copy the result of the following command into a browser to see the web app
echo "https://$($result.ResourceName).azurewebsites.net"

Azure PowerShell

Use azure-naming together with Azure PowerShell to create a web app and deploy code from GitHub:

# Get the resource name
$result = (azure-naming -r app -p Titanic$(Get-Random) -c Web -e dev -f json | ConvertFrom-Json)

# Replace the following URL with a public GitHub repo URL
$gitrepo = "https://github.com/Azure-Samples/app-service-web-dotnet-get-started.git"

# Create a resource group
New-AzResourceGroup -Location westeurope -Name $result.ResourceGroup

# Create an App Service plan in Free tier
New-AzAppServicePlan -Location westeurope -Name $result.ResourceName -ResourceGroupName $result.ResourceGroup -Tier Free

# Create a web app
New-AzWebApp -Location westeurope -Name $result.ResourceName -ResourceGroupName $result.ResourceGroup -AppServicePlan $result.ResourceName

# Configure GitHub deployment from your GitHub repo and deploy once
$PropertiesObject = @{
    repoUrl = "$gitrepo";
    branch = "master";
    isManualIntegration = "true";
}
Set-AzResource -Properties $PropertiesObject -ResourceGroupName $result.ResourceGroup -ResourceType Microsoft.Web/sites/sourcecontrols -ResourceName "$($result.ResourceName)/web" -ApiVersion 2015-08-01 -Force

# Copy the result of the following command into a browser to see the web app
Write-Output "https://$($result.ResourceName).azurewebsites.net"

Create your own naming convention

Microsoft offers best-practices when defining your naming convention:

Naming rules and restrictions:

Find out where dotnet-azure-naming is installed:

azure-naming --settings

The output will include the location:

"Location": "C:/Users/<user>/.dotnet/tools/.store/dotnet-azure-naming/1.0.0/dotnet-azure-naming/1.0.0/tools/net6.0/any"

Edit the appsettings.json file in above location:

{
  "DotnetAzureNamingSettings": {
    "AzureResourceTypesPath": "azure-resource-types.csv",
    "Environments": [
      {
        "Name": "Development",
        "Abbr": "dev"
      },
      {
        "Name": "Test",
        "Abbr": "test"
      },
      {
        "Name": "Staging",
        "Abbr": "stage"
      },
      {
        "Name": "Production",
        "Abbr": "prod"
      }
    ],
    "ResourceNameFormat": "{projectName} {componentName} {environment} {resourceType}",
    "ResourceGroupFormat": "{projectName} {componentName} {environment} rg"
  }
}

You may:

If you wish to change the default abbreviations of Azure resource types, edit the azure-resource-types.csv file:

Asset type;Resource provider namespace/Entity;Abbreviation;Transformer;Validator1;Validator2;Validator3;Validator4
AKS cluster;Microsoft.ContainerService/managedClusters;aks;alphanumericsUnderscoresHyphens;startWithAlphanumeric;endWithAlphanumeric;63characterLimit;
App Configuration store;Microsoft.AppConfiguration/configurationStores;appcs;alphanumericsUnderscoresHyphens;startWithAlphanumeric;endWithAlphanumeric;50characterLimit;atLeast5Characters
App Service environment;Microsoft.Web/sites;ase;alphanumericsHyphens;;;60characterLimit;atLeast2Characters
App Service plan;Microsoft.Web/serverFarms;plan;alphanumericsUnderscoresPeriodsHyphens;startWithAlphanumeric;endWithAlphanumericOrUnderscore;80characterLimit;
...

Open the file in a Spreadsheet Editor and make changes in the Abbreviation (third) column.

The original version of azure-resource-types.csv is located in Klabbets GitHub repo:

Changes made to appsettings.json and azure-resource-types.csv may be lost when updating dotnet-azure-naming. Make sure to take backups!

You can also make use of Environment Variables to configure the naming convention.

Set Environment Variables via the terminal:

setx DotnetAzureNamingSettings:AzureResourceTypesPath "c:\work\azure-resource-types.csv"
setx DotnetAzureNamingSettings:Environments:0:Name "Pre-Production"
setx DotnetAzureNamingSettings:Environments:0:Abbr "preprod"
setx DotnetAzureNamingSettings:Environments:1:Name "Production"
setx DotnetAzureNamingSettings:Environments:1:Abbr "prod"
setx DotnetAzureNamingSettings:Environments:2:Name " "
setx DotnetAzureNamingSettings:Environments:2:Abbr " "
setx DotnetAzureNamingSettings:Environments:3:Name " "
setx DotnetAzureNamingSettings:Environments:3:Abbr " "
setx DotnetAzureNamingSettings:ResourceNameFormat "prefix {projectName} {componentName} {environment} {resourceType} suffix"
setx DotnetAzureNamingSettings:ResourceGroupFormat "prefix {projectName} {componentName} {environment} rg suffix"

These settings will be preserved after an update of the tool.