Replies: 4 comments
-
I'm not sure if everyone would have the same name standardization practices, and, if not, these functions might not be a great fit for AVM. You can author these functions in a Bicep file and import them into others, though. Something like the following could be added to your repo and imported where needed: 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
@export()
func sanitizeStorageAccountName(name string, resourceToken string) string => '${take(replace('${toLower(take(name, 30))}-${resourceToken}', '-', ''), storageAccountPrefixLength)}${take(resourceToken, storageAccountTokenLength)}storage' |
Beta Was this translation helpful? Give feedback.
-
I was hoping for a solution where we could use the functions across hundreds of repositories, since all of our Azure templates need this naming. It sounds like an avm module that uses @export could work? I did not know that Bicep could export functions. |
Beta Was this translation helpful? Give feedback.
-
You can import functions, variables, and types from any Bicep module. As far as the Bicep compiler is concerned, there's no difference between an AVM module and a private one, so you could declare functions that are specific to your team's standards and then import them from a local file, a registry artifact, or a template spec. Using a registry or template spec would allow you to import the functions into as many git repositories as you need to. AVM isn't maintained by our team, but they have a contribution guide for Bicep modules if you'd like to pursue publishing this module into the AVM registry: https://azure.github.io/Azure-Verified-Modules/contributing/bicep/ |
Beta Was this translation helpful? Give feedback.
-
@jeskew @pamelafox I have been working on a naming convention function before, and it’s difficult to stay compliant with the On another note, I think the Naming Convention API could be very useful in combination with creating a Bicep local-deploy (experimental) extension. The extension could call this API (hosted somewhere) to generate resource names automatically that can then be used for the resources. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
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:
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:
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.
Beta Was this translation helpful? Give feedback.
All reactions