Skip to content

Commit 31d7686

Browse files
authored
Merge pull request #99 from microsoft/bicepnamefix
`fix`: A bug fix for prefix string too long error
2 parents 45e023f + 3f493cc commit 31d7686

File tree

3 files changed

+32
-18
lines changed

3 files changed

+32
-18
lines changed

infra/deploy_ai_foundry.bicep

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
// Creates Azure dependent resources for Azure AI studio
2+
@minLength(3)
3+
@maxLength(15)
4+
@description('Solution Name')
25
param solutionName string
36
param solutionLocation string
47
param keyVaultName string
@@ -9,7 +12,8 @@ param aiServicesEndpoint string
912
param aiServicesKey string
1013
param aiServicesId string
1114

12-
var storageName = '${solutionName}hubst'
15+
param storageName string = '${solutionName}hubst'
16+
1317
var storageSkuName = 'Standard_LRS'
1418
var aiServicesName = '${solutionName}-ais'
1519
var workspaceName = '${solutionName}-log'
@@ -40,7 +44,9 @@ resource logAnalytics 'Microsoft.OperationalInsights/workspaces@2023-09-01' = {
4044
}
4145

4246

43-
var storageNameCleaned = replace(storageName, '-', '')
47+
var storageNameCleaned = replace(replace(replace(replace('${storageName}cast', '-', ''), '_', ''), '.', ''),'/', '')
48+
49+
4450

4551

4652
resource storage 'Microsoft.Storage/storageAccounts@2022-09-01' = {

infra/main.bicep

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
@minLength(3)
2-
@maxLength(20)
3-
@description('Prefix for all resources created by this template. This prefix will be used to create unique names for all resources. The prefix must be unique within the resource group.')
4-
param Prefix string
2+
@description('Prefix for all resources created by this template. This should be 3-20 characters long. If your provide a prefix longer than 20 characters, it will be truncated to 20 characters.')
3+
param Prefix string
54

5+
var safePrefix = length(Prefix) > 20 ? substring(Prefix, 0, 20) : Prefix
66

77
@allowed([
88
'australiaeast'
@@ -33,9 +33,9 @@ param Prefix string
3333
param AzureAiServiceLocation string // The location used for all deployed resources. This location must be in the same region as the resource group.
3434
param capacity int = 5
3535

36-
var uniqueId = toLower(uniqueString(subscription().id, Prefix, resourceGroup().location))
36+
var uniqueId = toLower(uniqueString(subscription().id, safePrefix, resourceGroup().location))
3737
var UniquePrefix = 'cm${padLeft(take(uniqueId, 12), 12, '0')}'
38-
var ResourcePrefix = take('cm${Prefix}${UniquePrefix}', 15)
38+
var ResourcePrefix = take('cm${safePrefix}${UniquePrefix}', 15)
3939
var imageVersion = 'latest'
4040
var location = resourceGroup().location
4141
var dblocation = resourceGroup().location
@@ -47,7 +47,7 @@ var deploymentType = 'GlobalStandard'
4747
var containerName = 'appstorage'
4848
var llmModel = 'gpt-4o'
4949
var storageSkuName = 'Standard_LRS'
50-
var storageContainerName = '${ResourcePrefix}cast'
50+
var storageContainerName = replace(replace(replace(replace('${ResourcePrefix}cast', '-', ''), '_', ''), '.', ''),'/', '')
5151
var gptModelVersion = '2024-08-06'
5252
var azureAiServicesName = '${ResourcePrefix}-ais'
5353

infra/main.json

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,15 @@
55
"_generator": {
66
"name": "bicep",
77
"version": "0.35.1.17967",
8-
"templateHash": "12546479610758564230"
8+
"templateHash": "18182441225742462111"
99
}
1010
},
1111
"parameters": {
1212
"Prefix": {
1313
"type": "string",
1414
"minLength": 3,
15-
"maxLength": 20,
1615
"metadata": {
17-
"description": "Prefix for all resources created by this template. This prefix will be used to create unique names for all resources. The prefix must be unique within the resource group."
16+
"description": "Prefix for all resources created by this template. This should be 3-20 characters long. If your provide a prefix longer than 20 characters, it will be truncated to 20 characters."
1817
}
1918
},
2019
"AzureAiServiceLocation": {
@@ -54,9 +53,10 @@
5453
}
5554
},
5655
"variables": {
57-
"uniqueId": "[toLower(uniqueString(subscription().id, parameters('Prefix'), resourceGroup().location))]",
56+
"safePrefix": "[if(greater(length(parameters('Prefix')), 20), substring(parameters('Prefix'), 0, 20), parameters('Prefix'))]",
57+
"uniqueId": "[toLower(uniqueString(subscription().id, variables('safePrefix'), resourceGroup().location))]",
5858
"UniquePrefix": "[format('cm{0}', padLeft(take(variables('uniqueId'), 12), 12, '0'))]",
59-
"ResourcePrefix": "[take(format('cm{0}{1}', parameters('Prefix'), variables('UniquePrefix')), 15)]",
59+
"ResourcePrefix": "[take(format('cm{0}{1}', variables('safePrefix'), variables('UniquePrefix')), 15)]",
6060
"imageVersion": "latest",
6161
"location": "[resourceGroup().location]",
6262
"dblocation": "[resourceGroup().location]",
@@ -68,7 +68,7 @@
6868
"containerName": "appstorage",
6969
"llmModel": "gpt-4o",
7070
"storageSkuName": "Standard_LRS",
71-
"storageContainerName": "[format('{0}cast', variables('ResourcePrefix'))]",
71+
"storageContainerName": "[replace(replace(replace(replace(format('{0}cast', variables('ResourcePrefix')), '-', ''), '_', ''), '.', ''), '/', '')]",
7272
"gptModelVersion": "2024-08-06",
7373
"azureAiServicesName": "[format('{0}-ais', variables('ResourcePrefix'))]",
7474
"aiModelDeployments": [
@@ -618,12 +618,17 @@
618618
"_generator": {
619619
"name": "bicep",
620620
"version": "0.35.1.17967",
621-
"templateHash": "4382273497899479323"
621+
"templateHash": "8013960718059965025"
622622
}
623623
},
624624
"parameters": {
625625
"solutionName": {
626-
"type": "string"
626+
"type": "string",
627+
"minLength": 3,
628+
"maxLength": 15,
629+
"metadata": {
630+
"description": "Solution Name"
631+
}
627632
},
628633
"solutionLocation": {
629634
"type": "string"
@@ -648,10 +653,13 @@
648653
},
649654
"aiServicesId": {
650655
"type": "string"
656+
},
657+
"storageName": {
658+
"type": "string",
659+
"defaultValue": "[format('{0}hubst', parameters('solutionName'))]"
651660
}
652661
},
653662
"variables": {
654-
"storageName": "[format('{0}hubst', parameters('solutionName'))]",
655663
"storageSkuName": "Standard_LRS",
656664
"aiServicesName": "[format('{0}-ais', parameters('solutionName'))]",
657665
"workspaceName": "[format('{0}-log', parameters('solutionName'))]",
@@ -663,7 +671,7 @@
663671
"aiProjectName": "[format('{0}-prj', parameters('solutionName'))]",
664672
"aiProjectFriendlyName": "[variables('aiProjectName')]",
665673
"aiSearchName": "[format('{0}-srch', parameters('solutionName'))]",
666-
"storageNameCleaned": "[replace(variables('storageName'), '-', '')]"
674+
"storageNameCleaned": "[replace(replace(replace(replace(format('{0}cast', parameters('storageName')), '-', ''), '_', ''), '.', ''), '/', '')]"
667675
},
668676
"resources": [
669677
{

0 commit comments

Comments
 (0)