-
Notifications
You must be signed in to change notification settings - Fork 818
Description
Is your feature request related to a problem? Please describe.
I maintain many azd templates. Each template takes in an environment name, and then provisions some number of Azure resources. We like to name the resources based off the environment name, so that developers can easily find/recognize them in the Portal.
Unfortunately, that means we need to dynamically come up with Azure resource names that meet the many varied Azure resource naming rule constraints.
For example, consider this Bicep to compute an acceptable Azure storage name:
// See: https://learn.microsoft.com/azure/storage/common/storage-account-overview#storage-account-name
var storageAccountTokenLength = 5 // Number of characters from resourceToken to use (can be adjusted if needed)
var storageSuffixLength = length('storage') // Length of 'storage'
var storageAccountPrefixLength = 24 - storageAccountTokenLength - storageSuffixLength // Calculated for maintainability
var prefix = '${toLower(take(name, 30))}-${resourceToken}'
var prefixWithoutHyphens = replace(prefix, '-', '')
var storageAccountName = '${take(prefixWithoutHyphens, storageAccountPrefixLength)}${take(resourceToken, storageAccountTokenLength)}storage'
It adds a lot of Bicep to our templates and is easy to mess up due to Azure naming rules differing so much.
Describe the solution you'd like
We were thinking Bicep could have a built-in function for sanitizing names:
var functionAppName = sanitizeName($name, 'Microsoft.Web/sites')
var storageAccountName = sanitizeName($name, 'Microsoft.Storage/storageAccounts')
var blobContainerName = sanitizeName($name, 'Microsoft.Storage/storageAccounts/blobServices/containers')
var apimName = sanitizeName($name, 'Microsoft.ApiManagement/service')
When I asked @anthony-c-martin for his thoughts, he said that one approach may be a reusable function via AVM and started an example:
View in Bicep Playground
So maybe this is a feature request for the avm modules, but I thought I'd start here.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status