This Bicep module helps automate resource name generation following the recommended naming convention and abbreviations for Azure resource types.
This module is made to be fully customizable and adapt to user defined naming convention (including custom resource abbreviation) and it's aim to support the user in any name generation requirements providing not only a unique name specific for the current deployment but also additional support output to be manipulated in the bicep main deployment.
Inspired by Terraform module/implementation, this project is a reworking of the great job done by Nikolaos Antoniou
The base of the project is the azure.resources.definition.json
file.
This JSON file is a configuration file that contains all rules used for name generation. The file is composed of an array of objects (one for each resource) with the following structure:
{
"name": "app_service",
"length": {
"min": 2,
"max": 60
},
"regex": "^(?=.{2,60}$)[a-z0-9][a-zA-Z0-9-]+[a-z0-9]",
"scope": "global",
"prefix": "app",
"dashes": true
}
The attribute meanings are:
Attribute | Description |
---|---|
name | Resource name, this will be used as name for the resource call in the module without "_" |
length | Resource name minimum and the maximum length |
regex | Regex the resource name should match |
scope | Azure scope in which the name must be unique (can be global, subscription, resourceGroup, region or parent) |
prefix | Defined prefix assigned to the resource |
dashes | If the name accepts dash (-) in the name |
Most of this information can be obained from the official Microsoft Documentation
Due to the fact that the resource names have to be known at Bicep compile-time, we have to pre-populate an object with all possible resource names and provide it as parameter to the Bicep file deploying the workload. As a consequence we need to have a subscription-level deployment as entry-point.
for this reason, we have the azure.deploy.bicep
(subscription-level deployment) that includes the aznames.module.bicep
and pass the output (the object including all the names) to the workload.bicep
that contains all the required Azure resources for the solution.
Parameter | Description | Type | Default | Required |
---|---|---|---|---|
suffix | Suffix parts to be included in the naming | array(string) | [appdemo,dev] | no |
uniquifier | The string be used as uniquifuer | string | resourceGroup().id | no |
uniquifierLength | The number of characters in the unique part | int | 3 | no |
useDashes | Use dash (-) as delimiter | bool | true | no |
Note: the module doesn't support prefix as this is not recommended. if you need to add a prefix, like company name or azure region, you can add it manually or just reference them as tags or at higher level like subscription or management group.
Property | Description | Type |
---|---|---|
refName | The reference name without the uniquifier - useful for loops and resource group scoped resources | string |
uniName | The unique name including the uniquifier | string |
prefix | The prefix of the resources for your own name creating | string |
maxLength | Max number of characters for the resource | int |
scope | Scope in which the name must be unique | string |
dashes | If you can use dashes in the name | bool |
Every resource will have an output with the following format:
appService = {
refName = "app-suffix1-suffixN"
uniName = "app-suffix1-suffixN-uniquifier"
prefix = "app"
maxLength = 60
scope = "global"
dashes = true
}
A Starter-Pack tool has been created to showcase how to use this module and how to create the required bicep file structure to safely deploy any workload. You will find it in the starter-pack
folder of this repository.
The starter pack will create a resource group with the following Azure service instances:
- 1 Azure Webapp
- 1 Azure App Service Plan
- 1 Azure Storage Account (deployed using a separate bicep module)
- 3 Azure Storage Accounts (deployed using a bicep loop)
-
Open the Azure CLI directly from the Azure Portal
-
Clone the repository
git clone https://github.com/francesco-sodano/AZNames-bicep
-
Move to the starter-pack folder.
cd AZNames-bicep/starter-pack
-
Deploy the bicep main file
az deployment sub create --location "West Europe" --template-file ./azure.deploy.bicep --parameters @azure.deploy.parameters.json
Don't forget to cleanup afterward to avoid any unnecessary costs:
az group delete --resource-group rg-demobicep-dev
This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.
TBD - prepare the GitHub custom template for issues to include additional resources
Install the EPS templating module:
Install-Module EPS
Then run the PowerShell script:
./scripts/Invoke-AzNamesTemplate.ps1 > ./starter-pack/modules/aznames.module.bicep