Skip to content

Commit 4294e91

Browse files
authored
Merge pull request #70 from Azure-Samples/feat/customizable-resource-naming
feat: add customizable resource naming with snippymcplab branding
2 parents 8a94012 + 1c066cb commit 4294e91

File tree

3 files changed

+27
-13
lines changed

3 files changed

+27
-13
lines changed

infra/app/api.bicep

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ param maximumInstanceCount int = 100
1212
param identityId string = ''
1313
param identityClientId string = ''
1414
param resourceToken string
15+
param actualSuffix string
1516

1617
param runtimeName string = 'python'
1718
param runtimeVersion string = '3.11'
@@ -28,7 +29,7 @@ var applicationInsightsIdentity = 'ClientId=${identityClientId};Authorization=AA
2829
module appServicePlan 'br/public:avm/res/web/serverfarm:0.1.1' = {
2930
name: 'appserviceplan'
3031
params: {
31-
name: '${abbrs.webServerFarms}${resourceToken}'
32+
name: '${abbrs.webServerFarms}${resourceToken}-${actualSuffix}'
3233
location: regionSelector.getFlexConsumptionRegion(location)
3334
tags: tags
3435
sku: {

infra/main.bicep

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ param environmentName string
1515
})
1616
param location string
1717

18+
@description('Optional numeric suffix for resource names (e.g., 56093778). Auto-generated if not provided.')
19+
param nameSuffix string = ''
20+
1821
@description('Id of the user or app to assign application roles')
1922
param principalId string = ''
2023

@@ -50,16 +53,22 @@ param appRegistrationScopeId string = '' // Set via 'azd env set APP_REGISTRAT
5053
import * as regionSelector from './app/util/region-selector.bicep'
5154
var abbrs = loadJsonContent('./abbreviations.json')
5255

53-
var resourceToken = toLower(uniqueString(subscription().id, environmentName, location))
56+
// Auto-generate suffix if not provided
57+
var autoSuffix = toLower(take(uniqueString(subscription().id, environmentName, location), 8))
58+
var actualSuffix = !empty(nameSuffix) ? nameSuffix : autoSuffix
59+
60+
// Base name for all resources
61+
var resourceToken = 'snippymcplab'
62+
5463
var tags = { 'azd-env-name': environmentName }
55-
var functionAppName = !empty(apiServiceName) ? apiServiceName : '${abbrs.webSitesFunctions}api-${resourceToken}'
64+
var functionAppName = !empty(apiServiceName) ? apiServiceName : '${abbrs.webSitesFunctions}api-${resourceToken}-${actualSuffix}'
5665
var deploymentStorageContainerName = 'app-package-${take(functionAppName, 32)}-${take(toLower(uniqueString(functionAppName, resourceToken)), 7)}'
5766

58-
var storageAccountActualName = !empty(storageAccountName) ? storageAccountName : '${abbrs.storageStorageAccounts}${resourceToken}'
67+
var storageAccountActualName = !empty(storageAccountName) ? storageAccountName : '${abbrs.storageStorageAccounts}${resourceToken}${actualSuffix}'
5968

6069
// Organize resources in a resource group
6170
resource rg 'Microsoft.Resources/resourceGroups@2021-04-01' = {
62-
name: !empty(resourceGroupName) ? resourceGroupName : '${abbrs.resourcesResourceGroups}${environmentName}'
71+
name: !empty(resourceGroupName) ? resourceGroupName : '${abbrs.resourcesResourceGroups}${environmentName}-${resourceToken}-${actualSuffix}'
6372
location: location
6473
tags: tags
6574
}
@@ -71,7 +80,7 @@ module apiUserAssignedIdentity 'br/public:avm/res/managed-identity/user-assigned
7180
params: {
7281
location: location
7382
tags: tags
74-
name: !empty(apiUserAssignedIdentityName) ? apiUserAssignedIdentityName : '${abbrs.managedIdentityUserAssignedIdentities}api-${resourceToken}'
83+
name: !empty(apiUserAssignedIdentityName) ? apiUserAssignedIdentityName : '${abbrs.managedIdentityUserAssignedIdentities}api-${resourceToken}-${actualSuffix}'
7584
}
7685
}
7786

@@ -130,8 +139,8 @@ module monitoring 'app/monitoring.bicep' = {
130139
params: {
131140
location: location
132141
tags: tags
133-
logAnalyticsName: !empty(logAnalyticsName) ? logAnalyticsName : '${abbrs.operationalInsightsWorkspaces}${resourceToken}'
134-
applicationInsightsName: !empty(applicationInsightsName) ? applicationInsightsName : '${abbrs.insightsComponents}${resourceToken}'
142+
logAnalyticsName: !empty(logAnalyticsName) ? logAnalyticsName : '${abbrs.operationalInsightsWorkspaces}${resourceToken}-${actualSuffix}'
143+
applicationInsightsName: !empty(applicationInsightsName) ? applicationInsightsName : '${abbrs.insightsComponents}${resourceToken}-${actualSuffix}'
135144
}
136145
}
137146

@@ -156,7 +165,7 @@ module openai './app/ai/cognitive-services.bicep' = {
156165
location: regionSelector.getAiServicesRegion(location, chatModelName, embeddingModelName)
157166
tags: tags
158167
chatModelName: chatModelName
159-
aiServicesName: '${abbrs.cognitiveServicesAccounts}${resourceToken}'
168+
aiServicesName: '${abbrs.cognitiveServicesAccounts}${resourceToken}-${actualSuffix}'
160169
embeddingModelName: embeddingModelName
161170
}
162171
}
@@ -194,7 +203,7 @@ module cosmosDb './app/cosmos-db.bicep' = {
194203
params: {
195204
location: location
196205
tags: tags
197-
accountName: '${abbrs.documentDBDatabaseAccounts}${resourceToken}'
206+
accountName: '${abbrs.documentDBDatabaseAccounts}${resourceToken}-${actualSuffix}'
198207
databaseName: cosmosDatabaseName
199208
containerName: cosmosContainerName
200209
dataContributorIdentityIds: [
@@ -212,6 +221,7 @@ module api './app/api.bicep' = {
212221
location: regionSelector.getFlexConsumptionRegion(location)
213222
tags: tags
214223
resourceToken: resourceToken
224+
actualSuffix: actualSuffix
215225
applicationInsightsName: monitoring.outputs.applicationInsightsName
216226
storageAccountName: storage.outputs.name
217227
deploymentStorageContainerName: deploymentStorageContainerName
@@ -248,7 +258,7 @@ module apim './app/apim.bicep' = {
248258
name: 'apim'
249259
scope: rg
250260
params: {
251-
name: !empty(apimServiceName) ? apimServiceName : '${abbrs.apiManagementService}${resourceToken}'
261+
name: !empty(apimServiceName) ? apimServiceName : '${abbrs.apiManagementService}${resourceToken}-${actualSuffix}'
252262
location: location
253263
tags: tags
254264
publisherName: apimPublisherName
@@ -279,8 +289,8 @@ module dts './app/dts.bicep' = {
279289
scope: rg
280290
name: 'dtsResource'
281291
params: {
282-
name: !empty(dtsName) ? dtsName : '${abbrs.dts}${resourceToken}'
283-
taskhubname: !empty(taskHubName) ? taskHubName : '${abbrs.taskhub}${resourceToken}'
292+
name: !empty(dtsName) ? dtsName : '${abbrs.dts}${resourceToken}-${actualSuffix}'
293+
taskhubname: !empty(taskHubName) ? taskHubName : '${abbrs.taskhub}${resourceToken}${actualSuffix}'
284294
location: location
285295
tags: tags
286296
ipAllowlist: [

infra/main.parameters.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
"principalId": {
1212
"value": "${AZURE_PRINCIPAL_ID}"
1313
},
14+
"nameSuffix": {
15+
"value": "${NAME_SUFFIX=}"
16+
},
1417
"appRegistrationClientId": {
1518
"value": "${APP_REGISTRATION_CLIENT_ID=}"
1619
},

0 commit comments

Comments
 (0)