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

Create naming conventions for resources #556

Closed
glennmusa opened this issue Dec 3, 2021 · 3 comments · Fixed by #558 or #571
Closed

Create naming conventions for resources #556

glennmusa opened this issue Dec 3, 2021 · 3 comments · Fixed by #558 or #571
Assignees
Labels
core New feature or request

Comments

@glennmusa
Copy link
Contributor

glennmusa commented Dec 3, 2021

Benefit/Result/Outcome

So that deployed resources adopt generally accepted naming practices while providing a single place in source to modify the naming convention.

Description

We can use Bicep's string interpolation to create naming conventions and use Bicep's replace() function to do token replacement.

For example, given a resourcePrefix=foo and resourceSuffix=bar, here's how a naming convention could be defined, with reserved terms like <x>_token used for token replacement.

  1. First, we define the naming convention:

  2. Then, we could do token replacement for resource type abbreviations. For example, here on L27 generating a resource group naming convention like foo-rg-mlz_token-bar:

    • 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')
  3. Finally, using another replace() call to replace the next token, mlz_token. For example, here on L44 generating a hub resource group name like: foo-rg-hub-bar:

    • // HUB NAMES
      var hubResourceGroupName = replace(resourceGroupNamingConvention, 'mlz_token', 'hub')
      var hubLogStorageAccountName = replace(storageAccountNamingConvention, 'mlz_token', 'hub')
      var hubVirtualNetworkName = replace(virtualNetworkNamingConvention, 'mlz_token', 'hub')
      var hubNetworkSecurityGroupName = replace(networkSecurityGroupNamingConvention, 'mlz_token', 'hub')
      var hubSubnetName = replace(subnetNamingConvention, 'mlz_token', 'hub')
      // IDENTITY NAMES
      var identityResourceGroupName = replace(resourceGroupNamingConvention, 'mlz_token', 'identity')
      var identityLogStorageAccountName = replace(storageAccountNamingConvention, 'mlz_token', 'id')
      var identityVirtualNetworkName = replace(virtualNetworkNamingConvention, 'mlz_token', 'identity')
      var identityNetworkSecurityGroupName = replace(networkSecurityGroupNamingConvention, 'mlz_token', 'identity')
      var identitySubnetName = replace(subnetNamingConvention, 'mlz_token', 'identity')
      // OPERATIONS NAMES
      var operationsResourceGroupName = replace(resourceGroupNamingConvention, 'mlz_token', 'operations')
      var operationsLogStorageAccountName = replace(storageAccountNamingConvention, 'mlz_token', 'ops')
      var operationsVirtualNetworkName = replace(virtualNetworkNamingConvention, 'mlz_token', 'operations')
      var operationsNetworkSecurityGroupName = replace(networkSecurityGroupNamingConvention, 'mlz_token', 'operations')
      var operationsSubnetName = replace(subnetNamingConvention, 'mlz_token', 'operations')
      // SHARED SERVICES NAMES
      var sharedServicesResourceGroupName = replace(resourceGroupNamingConvention, 'mlz_token', 'sharedServices')
      var sharedServicesLogStorageAccountName = replace(storageAccountNamingConvention, 'mlz_token', 'svcs')
      var sharedServicesVirtualNetworkName = replace(virtualNetworkNamingConvention, 'mlz_token', 'sharedServices')
      var sharedServicesNetworkSecurityGroupName = replace(networkSecurityGroupNamingConvention, 'mlz_token', 'sharedServices')
      var sharedServicesSubnetName = replace(subnetNamingConvention, 'mlz_token', 'sharedServices')
      // LOG ANALYTICS NAMES
      var logAnalyticsWorkspaceName = replace(logAnalyticsWorkspaceNamingConvention, 'mlz_token', 'operations')
      // FIREWALL NAMES
      var firewallName = replace(firewallNamingConvention, 'mlz_token', 'hub')
      var firewallPolicyName = replace(firewallPolicyNamingConvention, 'mlz_token', 'hub')
      var firewallClientIpConfigurationName = replace(ipConfigurationNamingConvention, 'mlz_token', 'afw-client')
      var firewallClientPublicIPAddressName = replace(publicIpAddressNamingConvention, 'mlz_token', 'afw-client')
      var firewallManagementIpConfigurationName = replace(ipConfigurationNamingConvention, 'mlz_token', 'afw-mgmt')
      var firewallManagementPublicIPAddressName = replace(publicIpAddressNamingConvention, 'mlz_token', 'afw-mgmt')
      // BASTION NAMES
      var bastionHostName = replace(bastionHostNamingConvention, 'mlz_token', 'hub')
      var bastionHostPublicIPAddressName = replace(publicIpAddressNamingConvention, 'mlz_token', 'bas')
      var bastionHostIPConfigurationName = replace(ipConfigurationNamingConvention, 'mlz_token', 'bas')
      var linuxNetworkInterfaceName = replace(networkInterfaceNamingConvention, 'mlz_token', 'bas-linux')
      var linuxNetworkInterfaceIpConfigurationName = replace(ipConfigurationNamingConvention, 'mlz_token', 'bas-linux')
      var linuxVmName = replace(virtualMachineNamingConvention, 'mlz_token', 'bas-linux')
      var windowsNetworkInterfaceName = replace(networkInterfaceNamingConvention, 'mlz_token', 'bas-windows')
      var windowsNetworkInterfaceIpConfigurationName = replace(ipConfigurationNamingConvention, 'mlz_token', 'bas-windows')
      var windowsVmName = replace(virtualMachineNamingConvention, 'mlz_token', 'bas-windows')

Acceptance Criteria

  • Adopt a naming convention for the resources named at mlz.bicep
  • Use the recommended abbreviations where possible
  • Provide an obvious mechanism to override naming conventions
  • Document how to override naming conventions
  • All resource names are in lower case
  • An additional optional parameter is defined as resourcePostfix which allows deploying into the same subscriptions but different regions. It will default to "mlz"
  • Include resourcePostfix in automatic tags.
  • The seed for unique() calculations is the concatenation of resourcePrefix and resourcePostfix
  • 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 Author

Created this to address some of the acceptance criteria in #549

@glennmusa glennmusa self-assigned this Dec 3, 2021
@glennmusa
Copy link
Contributor Author

Started this work at glenn/namingConventions

@brooke-hamilton
Copy link
Contributor

@glennmusa I added these acceptance criteria from #503 and #549. I will close those backlog items.

  • All resource names are in lower case
  • An additional optional parameter is defined as resourcePostfix which allows deploying into the same subscriptions but different regions. It will default to "mlz"
  • Include resourcePostfix in automatic tags.
  • The seed for unique() calculations is the concatenation of resourcePrefix and resourcePostfix
  • 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.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core New feature or request
Projects
None yet
2 participants