-
Notifications
You must be signed in to change notification settings - Fork 268
Description
Ideally, a decision needs to be made for Aspire GA for how resource names are generated.
From @tg-msft:
I want to have a “name strategy” that by default keeps them stable but also allows you to randomize aggressively if desired for niche scenarios. Stable requires tracking the full namespace though to use kv2 occasionally instead of kv277327222773 always. We also need to be smarter about the various lengths (i.e. using a prefix with the first 24 identical characters for two Storage accounts should throw).
azd
For naming resources, azd is following the next strategy:
-
- Creates a unique hash using the resource group:
var resourceToken = uniqueString(resourceGroup().id)-
- Manage identity and resources which supports a name with dashes. Use a prefix depending on the resource followed by a dash and the unique hash.
name: 'mi-${resourceToken}'-
- Container registry and resources which don't support dashes. Follow the previous rule but remove all dashes from the result name.
name: replace('acr-${resourceToken}', '-', '')-
- Role assignments and resources which might be more than one in the same deployment. The base rule of prefix creates a collision when having more than one. The name is a uniqueId created from the resource inputs:
name: guid(containerRegistry.id, managedIdentity.id, subscriptionResourceId('Microsoft.Authorization/roleDefinitions', '7f951dda-4ed3-4680-a7ca-43fe172d538d'))-
- Secure outputs. Azd creates a key vault for resources which requires to set secrets and needs to be accessible to azd for deployment. This strategy prevents from having sensitive data as bicep outputs. For example, instead of setting the connection string for a DB as a bicep output, the connection string is saved with a key vault secret. Azd defines a key vault account for each resource expressing the need of secret outputs. To name a key vaults, azd follows the next strategy:
name: replace('kv${resourceName}${resourceToken}', '-', '')Note: if the resouceName is large enough and adding kv and ${resourceToken}' goes beyond 24 characters, deployment fails because key vault accounts names can't be greater than 24 characters. To mitigate this, azd ensures that resourceName is never greater than 12 characters, by producing a hash from the resourceName.
Aspire + Cdk
Bicep modules created by Aspire utilize the Cdk, which writes the next naming pattern:
name: toLower(take(concat('${resourceName}', uniqueString(resourceGroup().id)), 24))while the strategy secures the names with no dashes, it is still vulnerable to long resource names.