Skip to content

Commit

Permalink
1111 mlz add ons update component order in naming convention (#1118)
Browse files Browse the repository at this point in the history
* issue 1111

* naming convention and prefix count

* GitHub Action: Build Bicep to JSON

* Fixed max length in regex

* Alphabetized params

* GitHub Action: Build Bicep to JSON

* Alphabetized params & var value

* GitHub Action: Build Bicep to JSON

* Alphabetized param, Removed empty line

* GitHub Action: Build Bicep to JSON

---------

Co-authored-by: github-actions <[email protected]>
Co-authored-by: Jason Masten <[email protected]>
  • Loading branch information
3 people authored Oct 29, 2024
1 parent 87450b7 commit cb012df
Show file tree
Hide file tree
Showing 7 changed files with 128 additions and 50 deletions.
6 changes: 3 additions & 3 deletions src/bicep/form/mlz.portal.json
Original file line number Diff line number Diff line change
Expand Up @@ -229,13 +229,13 @@
"label": "Resource Naming Prefix",
"type": "Microsoft.Common.TextBox",
"defaultValue": "",
"toolTip": "Specify a prefix (min 3 and max 6 lowercase characters and numbers) to prepend to all resources.",
"toolTip": "Specify a prefix (min 1 and max 6 lowercase characters and numbers) to prepend to all resources.",
"constraints": {
"required": true,
"validations": [
{
"regex": "^[a-z][a-z0-9]{1,5}$",
"message": "The prefix must contain alphanumeric characters, begin with a letter, letters must be lowercase, and the length must be between 3 to 6 characters."
"regex": "^[a-z0-9]{1,6}$",
"message": "The prefix must contain alphanumeric characters, letters must be lowercase, and the length must be between 1 to 6 characters."
}
]
}
Expand Down
6 changes: 4 additions & 2 deletions src/bicep/mlz.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ targetScope = 'subscription'

// REQUIRED PARAMETERS

@minLength(3)
@minLength(1)
@maxLength(6)
@description('A prefix, 3-6 alphanumeric characters without whitespace, used to prefix resources and generate uniqueness for resources with globally unique naming requirements like Storage Accounts and Log Analytics Workspaces')
@description('A prefix, 1-6 alphanumeric characters without whitespace, used to prefix resources and generate uniqueness for resources with globally unique naming requirements like Storage Accounts and Log Analytics Workspaces')
param resourcePrefix string

@allowed([
Expand Down Expand Up @@ -725,10 +725,12 @@ module storage 'modules/storage.bicep' = {
blobsPrivateDnsZoneResourceId: networking.outputs.privateDnsZoneResourceIds.blob
//deployIdentity: deployIdentity
deploymentNameSuffix: deploymentNameSuffix
filesPrivateDnsZoneResourceId: networking.outputs.privateDnsZoneResourceIds.file
keyVaultUri: customerManagedKeys.outputs.keyVaultUri
location: location
logStorageSkuName: logStorageSkuName
mlzTags: logic.outputs.mlzTags
queuesPrivateDnsZoneResourceId: networking.outputs.privateDnsZoneResourceIds.queue
resourceGroupNames: resourceGroups.outputs.names
serviceToken: logic.outputs.tokens.service
storageEncryptionKeyName: customerManagedKeys.outputs.storageKeyName
Expand Down
102 changes: 75 additions & 27 deletions src/bicep/mlz.json

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions src/bicep/modules/linux-virtual-machine.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ resource virtualMachine 'Microsoft.Compute/virtualMachines@2021-04-01' = {
}
}

resource guestAttestationExtension 'Microsoft.Compute/virtualMachines/extensions@2021-03-01' = {
resource guestAttestationExtension 'Microsoft.Compute/virtualMachines/extensions@2024-03-01' = {
parent: virtualMachine
name: 'GuestAttestation'
location: location
Expand All @@ -128,7 +128,6 @@ resource guestAttestationExtension 'Microsoft.Compute/virtualMachines/extensions
type: 'GuestAttestation'
typeHandlerVersion: '1.0'
autoUpgradeMinorVersion: true
enableAutomaticUpgrade: true
settings: {
AttestationConfig: {
MaaSettings: {
Expand Down
15 changes: 11 additions & 4 deletions src/bicep/modules/naming-convention.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ param networkShortName string
param resourcePrefix string
param stampIndex string = '' // Optional: Added to support AVD deployments
param tokens object = {
purpose:'purpose_token'
resource: 'resource_token'
service: 'service_token'
}
Expand All @@ -33,8 +34,8 @@ var resourceAbbreviations = loadJsonContent('../data/resourceAbbreviations.json'
*/

var namingConvention = '${toLower(resourcePrefix)}-${empty(stampIndex) ? '' : '${stampIndex}-'}${tokens.resource}-${networkName}-${environmentAbbreviation}-${locationAbbreviation}'
var namingConvention_Service = '${toLower(resourcePrefix)}-${empty(stampIndex) ? '' : '${stampIndex}-'}${tokens.resource}-${tokens.service}-${networkName}-${environmentAbbreviation}-${locationAbbreviation}'
var namingConvention = '${toLower(resourcePrefix)}-${empty(stampIndex) ? '' : '${stampIndex}-'}${tokens.resource}-${networkName}-${locationAbbreviation}-${environmentAbbreviation}'
var namingConvention_Service = '${toLower(resourcePrefix)}-${empty(stampIndex) ? '' : '${stampIndex}-'}${tokens.resource}-${networkName}-${tokens.service}-${locationAbbreviation}-${environmentAbbreviation}'

/*
Expand Down Expand Up @@ -106,8 +107,14 @@ var names = {
routeTable: replace(namingConvention, tokens.resource, resourceAbbreviations.routeTables)
storageAccount: replace(replace(namingConvention_Service, tokens.resource, resourceAbbreviations.storageAccounts), networkName, networkShortName)
storageAccountDiagnosticSetting: replace(replace(namingConvention_Service, tokens.resource, resourceAbbreviations.diagnosticSettings), tokens.service, '${tokens.service}-${resourceAbbreviations.storageAccounts}')
storageAccountNetworkInterface: replace(replace(namingConvention_Service, tokens.resource, resourceAbbreviations.networkInterfaces), tokens.service, '${tokens.service}-${resourceAbbreviations.storageAccounts}')
storageAccountPrivateEndpoint: replace(replace(namingConvention_Service, tokens.resource, resourceAbbreviations.privateEndpoints), tokens.service, '${tokens.service}-${resourceAbbreviations.storageAccounts}')
storageAccountBlobNetworkInterface: replace(replace(namingConvention_Service, tokens.resource, resourceAbbreviations.networkInterfaces), tokens.service, '${resourceAbbreviations.storageAccounts}-blob')
storageAccountFileNetworkInterface: replace(replace(namingConvention_Service, tokens.resource, resourceAbbreviations.networkInterfaces), tokens.service, '${resourceAbbreviations.storageAccounts}-file')
storageAccountQueueNetworkInterface: replace(replace(namingConvention_Service, tokens.resource, resourceAbbreviations.networkInterfaces), tokens.service, '${resourceAbbreviations.storageAccounts}-queue')
storageAccountTableNetworkInterface: replace(replace(namingConvention_Service, tokens.resource, resourceAbbreviations.networkInterfaces), tokens.service, '${resourceAbbreviations.storageAccounts}-table')
storageAccountBlobPrivateEndpoint: replace(replace(namingConvention_Service, tokens.resource, resourceAbbreviations.privateEndpoints), tokens.service, '${resourceAbbreviations.storageAccounts}-blob')
storageAccountFilePrivateEndpoint: replace(replace(namingConvention_Service, tokens.resource, resourceAbbreviations.privateEndpoints), tokens.service, '${resourceAbbreviations.storageAccounts}-file')
storageAccountQueuePrivateEndpoint: replace(replace(namingConvention_Service, tokens.resource, resourceAbbreviations.privateEndpoints), tokens.service, '${resourceAbbreviations.storageAccounts}-queue')
storageAccountTablePrivateEndpoint: replace(replace(namingConvention_Service, tokens.resource, resourceAbbreviations.privateEndpoints), tokens.service, '${resourceAbbreviations.storageAccounts}-table')
subnet: replace(namingConvention, tokens.resource, resourceAbbreviations.subnets)
userAssignedIdentity: replace(namingConvention_Service, tokens.resource, resourceAbbreviations.userAssignedIdentities)
virtualMachine: replace(replace(replace(replace(namingConvention_Service, tokens.resource, resourceAbbreviations.virtualMachines), environmentAbbreviation, first(environmentAbbreviation)), networkName, ''), '-', '')
Expand Down
40 changes: 30 additions & 10 deletions src/bicep/modules/storage-account.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ Licensed under the MIT License.
*/

param blobsPrivateDnsZoneResourceId string
param filesPrivateDnsZoneResourceId string
param keyVaultUri string
param location string
param mlzTags object
param queuesPrivateDnsZoneResourceId string
param serviceToken string
param skuName string
param storageEncryptionKeyName string
Expand All @@ -16,9 +18,27 @@ param tags object
param tier object
param userAssignedIdentityResourceId string

var zones = [
blobsPrivateDnsZoneResourceId
tablesPrivateDnsZoneResourceId
var subResources = [
{
id: blobsPrivateDnsZoneResourceId
nic: tier.namingConvention.storageAccountBlobNetworkInterface
pe: tier.namingConvention.storageAccountBlobPrivateEndpoint
}
{
id: filesPrivateDnsZoneResourceId
nic: tier.namingConvention.storageAccountFileNetworkInterface
pe: tier.namingConvention.storageAccountFilePrivateEndpoint
}
{
id: queuesPrivateDnsZoneResourceId
nic: tier.namingConvention.storageAccountQueueNetworkInterface
pe: tier.namingConvention.storageAccountQueuePrivateEndpoint
}
{
id: tablesPrivateDnsZoneResourceId
nic: tier.namingConvention.storageAccountTableNetworkInterface
pe: tier.namingConvention.storageAccountTablePrivateEndpoint
}
]

resource storageAccount 'Microsoft.Storage/storageAccounts@2023-01-01' = {
Expand Down Expand Up @@ -84,19 +104,19 @@ resource storageAccount 'Microsoft.Storage/storageAccounts@2023-01-01' = {
}
}

resource privateEndpoints 'Microsoft.Network/privateEndpoints@2023-04-01' = [for (zone, i) in zones: {
name: replace(tier.namingConvention.storageAccountPrivateEndpoint, serviceToken, '${split(split(zone, '/')[8], '.')[1]}-log')
resource privateEndpoints 'Microsoft.Network/privateEndpoints@2023-04-01' = [for (resource, i) in subResources: {
name: resource.pe
location: location
tags: union(contains(tags, 'Microsoft.Network/privateEndpoints') ? tags['Microsoft.Network/privateEndpoints'] : {}, mlzTags)
properties: {
customNetworkInterfaceName: replace(tier.namingConvention.storageAccountNetworkInterface, serviceToken, '${split(split(zone, '/')[8], '.')[1]}-log')
customNetworkInterfaceName: resource.nic
privateLinkServiceConnections: [
{
name: replace(tier.namingConvention.storageAccountPrivateEndpoint, serviceToken, '${split(split(zone, '/')[8], '.')[1]}-log')
name: resource.pe
properties: {
privateLinkServiceId: storageAccount.id
groupIds: [
split(split(zone, '/')[8], '.')[1]
split(split(resource.id, '/')[8], '.')[1]
]
}
}
Expand All @@ -107,7 +127,7 @@ resource privateEndpoints 'Microsoft.Network/privateEndpoints@2023-04-01' = [for
}
}]

resource privateDnsZoneGroups 'Microsoft.Network/privateEndpoints/privateDnsZoneGroups@2021-08-01' = [for (zone, i) in zones: {
resource privateDnsZoneGroups 'Microsoft.Network/privateEndpoints/privateDnsZoneGroups@2021-08-01' = [for (resource, i) in subResources: {
parent: privateEndpoints[i]
name: storageAccount.name
properties: {
Expand All @@ -116,7 +136,7 @@ resource privateDnsZoneGroups 'Microsoft.Network/privateEndpoints/privateDnsZone
name: 'ipconfig1'
properties: {
#disable-next-line use-resource-id-functions
privateDnsZoneId: zone
privateDnsZoneId: resource.id
}
}
]
Expand Down
6 changes: 4 additions & 2 deletions src/bicep/modules/storage.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ targetScope = 'subscription'
param blobsPrivateDnsZoneResourceId string
//param deployIdentity bool
param deploymentNameSuffix string
param filesPrivateDnsZoneResourceId string
param keyVaultUri string
param location string
param logStorageSkuName string
param mlzTags object
param queuesPrivateDnsZoneResourceId string
param resourceGroupNames array
param serviceToken string
param storageEncryptionKeyName string
Expand All @@ -25,9 +27,11 @@ module storageAccount 'storage-account.bicep' = [for (tier, i) in tiers: {
scope: resourceGroup(tier.subscriptionId, resourceGroupNames[i])
params: {
blobsPrivateDnsZoneResourceId: blobsPrivateDnsZoneResourceId
filesPrivateDnsZoneResourceId: filesPrivateDnsZoneResourceId
keyVaultUri: keyVaultUri
location: location
mlzTags: mlzTags
queuesPrivateDnsZoneResourceId: queuesPrivateDnsZoneResourceId
serviceToken: serviceToken
skuName: logStorageSkuName
storageEncryptionKeyName: storageEncryptionKeyName
Expand All @@ -40,5 +44,3 @@ module storageAccount 'storage-account.bicep' = [for (tier, i) in tiers: {
}]

output storageAccountResourceIds array = [for (tier, i) in tiers: storageAccount[i].outputs.id]


0 comments on commit cb012df

Please sign in to comment.