Skip to content

This Bicep module helps to automate resource name generation following the recommended naming convention and abbreviations for Azure resource types.

Notifications You must be signed in to change notification settings

francesco-sodano/AZNames-bicep

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

42 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

made-for-VSCode Open in Visual Studio Code

AzNames - A Bicep module for consistent naming in Azure

Introduction

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

Project Structure (and automation)

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

The AzNames Module

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.

Input Parameters

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.

Output

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
}

How to use the Starter Pack

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)

Deploy using Azure CLI

  1. Open the Azure CLI directly from the Azure Portal

  2. Clone the repository

    git clone https://github.com/francesco-sodano/AZNames-bicep
    
  3. Move to the starter-pack folder.

    cd AZNames-bicep/starter-pack
    
  4. Deploy the bicep main file

    az deployment sub create --location "West Europe" --template-file ./azure.deploy.bicep --parameters @azure.deploy.parameters.json
    

Clean up

Don't forget to cleanup afterward to avoid any unnecessary costs:

az group delete --resource-group rg-demobicep-dev

Contributing

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

Building the module

Install the EPS templating module:

Install-Module EPS

Then run the PowerShell script:

./scripts/Invoke-AzNamesTemplate.ps1 > ./starter-pack/modules/aznames.module.bicep

References

About

This Bicep module helps to automate resource name generation following the recommended naming convention and abbreviations for Azure resource types.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •