Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate a unique name from user input to use with multiple Bicep modules #503

Closed
brooke-hamilton opened this issue Nov 8, 2021 · 3 comments
Labels
spike A time-boxed effort to answer a question

Comments

@brooke-hamilton
Copy link
Contributor

Benefit/Result/Outcome

We need a simple proof-of-concept for generating a unique name based on user input, i.e., the resourcePrefix parameter, that can be passed to individual modules in order to ensure uniqueness, and also be consistent to preserve idempotency. Idempotency and uniqueness are conflicting goals, and we believe that using a user input like resourcePrefix is the best compromise between the two goals.

This issue will unblock #498.

Acceptance Criteria

  • User input generates a unique name using the Bicep uniqueString function.
  • The resulting unique string is passed to a module that creates a storage account using the unique string as part of the storage account name.
  • The storage account can be deployed multiple times without destroying and recreating, preserving idempotency.
@glennmusa
Copy link
Contributor

@ExchMaster pointed us to the "shared variables" pattern that could prove helpful for this work:

https://docs.microsoft.com/en-us/azure/azure-resource-manager/bicep/patterns-shared-variable-file#example-1-naming-prefixes

@vidyambala vidyambala added this to the Resource Naming milestone Nov 15, 2021
@brooke-hamilton brooke-hamilton changed the title Spike: Generate a unique name from user input to use with multiple Bicep modules Generate a unique name from user input to use with multiple Bicep modules Dec 5, 2021
@glennmusa
Copy link
Contributor

This could be OBE by the proposed changes stemming from #556.

In those proposed changes the resource prefix is prepended to resource names and the unique string is calculated for each deployment for the resources that need it (storage accounts, L28 in this example):

var namingConvention = '${resourcePrefix}-resource_token-mlz_token-${resourceSuffix}'
var bastionHostNamingConvention = replace(namingConvention, 'resource_token', 'bas')
var firewallNamingConvention = replace(namingConvention, 'resource_token', 'afw')
var firewallPolicyNamingConvention = replace(namingConvention, 'resource_token', 'afwp')
var ipConfigurationNamingConvention = replace(namingConvention, 'resource_token', 'ipconf')
var logAnalyticsWorkspaceNamingConvention = replace(namingConvention, 'resource_token', 'log')
var networkInterfaceNamingConvention = replace(namingConvention, 'resource_token', 'nic')
var networkSecurityGroupNamingConvention = replace(namingConvention, 'resource_token', 'nsg')
var publicIpAddressNamingConvention = replace(namingConvention, 'resource_token', 'pip')
var resourceGroupNamingConvention = replace(namingConvention, 'resource_token', 'rg')
var storageAccountNamingConvention = '${resourcePrefix}stmlz_token${uniqueString(resourcePrefix, guid(nowUtc))}' // we use unique string here to generate uniqueness
var subnetNamingConvention = replace(namingConvention, 'resource_token', 'snet')
var virtualMachineNamingConvention = replace(namingConvention, 'resource_token', 'vm')
var virtualNetworkNamingConvention = replace(namingConvention, 'resource_token', 'vnet')

@brooke-hamilton
Copy link
Contributor Author

This backlog item is superseded by #556.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
spike A time-boxed effort to answer a question
Projects
None yet
Development

No branches or pull requests

3 participants