Skip to content

Commit 25d6626

Browse files
author
Harmanpreet Kaur
committed
added bicep
1 parent 40fd989 commit 25d6626

7 files changed

Lines changed: 75 additions & 206 deletions

File tree

infra/deploy_ai_foundry.bicep

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
// Creates Azure dependent resources for Azure AI studio
2-
@minLength(3)
3-
@maxLength(15)
4-
@description('Solution Name')
52
param solutionName string
63
param solutionLocation string
74
param keyVaultName string
@@ -11,7 +8,6 @@ param managedIdentityObjectId string
118
param aiServicesEndpoint string
129
param aiServicesKey string
1310
param aiServicesId string
14-
1511
var abbrs = loadJsonContent('./abbreviations.json')
1612
var storageName = '${abbrs.storage.storageAccount}${solutionName}hubst'
1713
var storageSkuName = 'Standard_LRS'
@@ -27,7 +23,6 @@ var aiProjectFriendlyName = aiProjectName
2723
var aiSearchName = '${abbrs.ai.aiSearch}${solutionName}'
2824

2925

30-
3126
resource keyVault 'Microsoft.KeyVault/vaults@2022-07-01' existing = {
3227
name: keyVaultName
3328
}
@@ -45,9 +40,7 @@ resource logAnalytics 'Microsoft.OperationalInsights/workspaces@2023-09-01' = {
4540
}
4641

4742

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

5245

5346
resource storage 'Microsoft.Storage/storageAccounts@2022-09-01' = {
@@ -119,7 +112,7 @@ resource storageroleAssignment 'Microsoft.Authorization/roleAssignments@2022-04-
119112
}
120113

121114
resource aiHub 'Microsoft.MachineLearningServices/workspaces@2023-08-01-preview' = {
122-
name: azureAiHubName
115+
name: aiHubName
123116
location: location
124117
identity: {
125118
type: 'SystemAssigned'
@@ -136,7 +129,7 @@ resource aiHub 'Microsoft.MachineLearningServices/workspaces@2023-08-01-preview'
136129
kind: 'hub'
137130

138131
resource aiServicesConnection 'connections@2024-07-01-preview' = {
139-
name: '${azureAiHubName}-connection-AzureOpenAI'
132+
name: '${aiHubName}-connection-AzureOpenAI'
140133
properties: {
141134
category: 'AIServices'
142135
target: aiServicesEndpoint
@@ -305,5 +298,3 @@ output storageAccountName string = storageNameCleaned
305298

306299
output logAnalyticsId string = logAnalytics.id
307300
output storageAccountId string = storage.id
308-
309-
output projectConnectionString string = '${split(aiHubProject.properties.discoveryUrl, '/')[2]};${subscription().subscriptionId};${resourceGroup().name};${aiHubProject.name}'

infra/deploy_keyvault.bicep

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ resource keyVault 'Microsoft.KeyVault/vaults@2022-07-01' = {
3535
enabledForDeployment: true
3636
enabledForDiskEncryption: true
3737
enabledForTemplateDeployment: true
38+
enableSoftDelete: false
3839
enableRbacAuthorization: true
40+
enablePurgeProtection: true
3941
publicNetworkAccess: 'enabled'
4042
sku: {
4143
family: 'A'

infra/deploy_managed_identity.bicep

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,8 @@ param solutionName string
1010
param solutionLocation string
1111

1212
@description('Name')
13-
1413
param miName string
1514

16-
1715
resource managedIdentity 'Microsoft.ManagedIdentity/userAssignedIdentities@2023-01-31' = {
1816
name: miName
1917
location: solutionLocation

infra/main.bicep

Lines changed: 34 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
@minLength(3)
2-
32
@maxLength(10)
43
@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.')
54
param ResourcePrefix string
65
var abbrs = loadJsonContent('./abbreviations.json')
76

8-
97
@allowed([
108
'australiaeast'
119
'brazilsouth'
@@ -32,13 +30,24 @@ var abbrs = loadJsonContent('./abbreviations.json')
3230
'westus3'
3331
])
3432
@description('Location for all Ai services resources. This location can be different from the resource group location.')
35-
param AzureAiServiceLocation string // The location used for all deployed resources. This location must be in the same region as the resource group.
33+
param AiLocation string // The location used for all deployed resources. This location must be in the same region as the resource group.
3634
param capacity int = 5
3735

38-
var uniqueId = toLower(uniqueString(subscription().id, safePrefix, resourceGroup().location))
39-
var UniquePrefix = 'cm${padLeft(take(uniqueId, 12), 12, '0')}'
40-
var ResourcePrefix = take('cm${safePrefix}${UniquePrefix}', 15)
41-
var imageVersion = 'latest'
36+
37+
@description('A unique prefix for all resources in this deployment. This should be 3-10 characters long:')
38+
//param environmentName string
39+
var randomString = substring(uniqueString(resourceGroup().id), 0, 4)
40+
@description('The location used for all deployed resources')
41+
// Generate a unique string based on the base name and a unique identifier
42+
//var uniqueSuffix = uniqueString(resourceGroup().id, ResourcePrefix)
43+
44+
// Take the first 4 characters of the unique string to use as a suffix
45+
//var randomSuffix = substring(ResourcePrefix, 0, min(10, length(ResourcePrefix)))
46+
47+
// Combine the base name with the random suffix
48+
var finalName = '${ResourcePrefix}-${randomString}'
49+
50+
var imageVersion = 'rc1'
4251
var location = resourceGroup().location
4352
var dblocation = resourceGroup().location
4453
var cosmosdbDatabase = 'cmsadb'
@@ -48,15 +57,14 @@ var cosmosdbLogContainer = 'cmsalog'
4857
var deploymentType = 'GlobalStandard'
4958
var containerName = 'appstorage'
5059
var llmModel = 'gpt-4o'
60+
var prefixCleaned = replace(toLower(finalName), '-', '')
5161
var storageSkuName = 'Standard_LRS'
52-
5362
var storageContainerName = '${abbrs.storage.storageAccount}${prefixCleaned}'
5463
var gptModelVersion = '2024-08-06'
5564
var aiServicesName = '${abbrs.ai.aiServices}${prefixCleaned}'
5665

5766

5867

59-
6068
var aiModelDeployments = [
6169
{
6270
name: llmModel
@@ -70,26 +78,24 @@ var aiModelDeployments = [
7078
}
7179
]
7280

73-
resource azureAiServices 'Microsoft.CognitiveServices/accounts@2024-04-01-preview' = {
74-
name: azureAiServicesName
81+
resource aiServices 'Microsoft.CognitiveServices/accounts@2024-04-01-preview' = {
82+
name: aiServicesName
7583
location: location
7684
sku: {
7785
name: 'S0'
7886
}
7987
kind: 'AIServices'
8088
properties: {
81-
8289
customSubDomainName: aiServicesName
8390
apiProperties: {
8491
// statisticsEnabled: false
8592
}
86-
8793
}
8894
}
8995

9096
@batchSize(1)
91-
resource azureAiServicesDeployments 'Microsoft.CognitiveServices/accounts/deployments@2023-05-01' = [for aiModeldeployment in aiModelDeployments: {
92-
parent: azureAiServices //aiServices_m
97+
resource aiServicesDeployments 'Microsoft.CognitiveServices/accounts/deployments@2023-05-01' = [for aiModeldeployment in aiModelDeployments: {
98+
parent: aiServices //aiServices_m
9399
name: aiModeldeployment.name
94100
properties: {
95101
model: {
@@ -111,10 +117,8 @@ resource azureAiServicesDeployments 'Microsoft.CognitiveServices/accounts/deploy
111117
module managedIdentityModule 'deploy_managed_identity.bicep' = {
112118
name: 'deploy_managed_identity'
113119
params: {
114-
115120
miName:'${abbrs.security.managedIdentity}${prefixCleaned}'
116121
solutionName: prefixCleaned
117-
118122
solutionLocation: location
119123
}
120124
scope: resourceGroup(resourceGroup().name)
@@ -125,10 +129,8 @@ module managedIdentityModule 'deploy_managed_identity.bicep' = {
125129
module kvault 'deploy_keyvault.bicep' = {
126130
name: 'deploy_keyvault'
127131
params: {
128-
129132
keyvaultName: '${abbrs.security.keyVault}${prefixCleaned}'
130133
solutionName: prefixCleaned
131-
132134
solutionLocation: location
133135
managedIdentityObjectId:managedIdentityModule.outputs.managedIdentityOutput.objectId
134136
}
@@ -137,40 +139,38 @@ module kvault 'deploy_keyvault.bicep' = {
137139

138140

139141
// ==========AI Foundry and related resources ========== //
140-
module azureAifoundry 'deploy_ai_foundry.bicep' = {
142+
module aifoundry 'deploy_ai_foundry.bicep' = {
141143
name: 'deploy_ai_foundry'
142144
params: {
143-
solutionName: ResourcePrefix
144-
solutionLocation: AzureAiServiceLocation
145+
solutionName: prefixCleaned
146+
solutionLocation: AiLocation
145147
keyVaultName: kvault.outputs.keyvaultName
146148
gptModelName: llmModel
147149
gptModelVersion: gptModelVersion
148150
managedIdentityObjectId:managedIdentityModule.outputs.managedIdentityOutput.objectId
149-
aiServicesEndpoint: azureAiServices.properties.endpoint
150-
aiServicesKey: azureAiServices.listKeys().key1
151-
aiServicesId: azureAiServices.id
151+
aiServicesEndpoint: aiServices.properties.endpoint
152+
aiServicesKey: aiServices.listKeys().key1
153+
aiServicesId: aiServices.id
152154
}
153155
scope: resourceGroup(resourceGroup().name)
154156
}
155157

156158
module containerAppsEnvironment 'br/public:avm/res/app/managed-environment:0.9.1' = {
157-
name: toLower('${ResourcePrefix}conAppsEnv')
159+
name: toLower('${prefixCleaned}conAppsEnv')
158160
params: {
159-
logAnalyticsWorkspaceResourceId: azureAifoundry.outputs.logAnalyticsId
160-
name: toLower('${ResourcePrefix}manenv')
161+
logAnalyticsWorkspaceResourceId: aifoundry.outputs.logAnalyticsId
162+
name: toLower('${prefixCleaned}manenv')
161163
location: location
162164
zoneRedundant: false
163165
managedIdentities: managedIdentityModule
164166
}
165167
}
166168

167169
module databaseAccount 'br/public:avm/res/document-db/database-account:0.9.0' = {
168-
name: toLower('${ResourcePrefix}cosmos')
170+
name: toLower('${prefixCleaned}database')
169171
params: {
170172
// Required parameters
171-
172173
name: toLower('${abbrs.databases.cosmosDBDatabase}${prefixCleaned}databaseAccount')
173-
174174
// Non-required parameters
175175
enableAnalyticalStorage: true
176176
location: dblocation
@@ -234,9 +234,7 @@ module databaseAccount 'br/public:avm/res/document-db/database-account:0.9.0' =
234234
}
235235

236236
module containerAppFrontend 'br/public:avm/res/app/container-app:0.13.0' = {
237-
238237
name: toLower('${abbrs.containers.containerApp}${prefixCleaned}containerAppFrontend')
239-
240238
params: {
241239
managedIdentities: {
242240
systemAssigned: true
@@ -266,19 +264,15 @@ module containerAppFrontend 'br/public:avm/res/app/container-app:0.13.0' = {
266264
scaleMinReplicas: 1
267265
scaleMaxReplicas: 1
268266
environmentResourceId: containerAppsEnvironment.outputs.resourceId
269-
270267
name: toLower('${abbrs.containers.containerApp}${prefixCleaned}containerFrontend')
271-
272268
// Non-required parameters
273269
location: location
274270
}
275271
}
276272

277273

278274
resource containerAppBackend 'Microsoft.App/containerApps@2023-05-01' = {
279-
280275
name: toLower('${abbrs.containers.containerApp}${prefixCleaned}containerBackend')
281-
282276
location: location
283277
identity: {
284278
type: 'SystemAssigned'
@@ -331,7 +325,7 @@ resource containerAppBackend 'Microsoft.App/containerApps@2023-05-01' = {
331325
}
332326
{
333327
name: 'AZURE_OPENAI_ENDPOINT'
334-
value: 'https://${azureAifoundry.outputs.aiServicesName}.openai.azure.com/'
328+
value: 'https://${aifoundry.outputs.aiServicesName}.openai.azure.com/'
335329
}
336330
{
337331
name: 'MIGRATOR_AGENT_MODEL_DEPLOY'
@@ -361,26 +355,6 @@ resource containerAppBackend 'Microsoft.App/containerApps@2023-05-01' = {
361355
name: 'TERMINATION_MODEL_DEPLOY'
362356
value: llmModel
363357
}
364-
{
365-
name: 'AZURE_AI_AGENT_MODEL_DEPLOYMENT_NAME'
366-
value: llmModel
367-
}
368-
{
369-
name: 'AZURE_AI_AGENT_PROJECT_NAME'
370-
value: azureAifoundry.outputs.aiProjectName
371-
}
372-
{
373-
name: 'AZURE_AI_AGENT_RESOURCE_GROUP_NAME'
374-
value: resourceGroup().name
375-
}
376-
{
377-
name: 'AZURE_AI_AGENT_SUBSCRIPTION_ID'
378-
value: subscription().subscriptionId
379-
}
380-
{
381-
name: 'AZURE_AI_AGENT_PROJECT_CONNECTION_STRING'
382-
value: azureAifoundry.outputs.projectConnectionString
383-
}
384358
]
385359
resources: {
386360
cpu: 1
@@ -454,7 +428,7 @@ var openAiContributorRoleId = 'a001fd3d-188f-4b5d-821b-7da978bf7442' // Fixed R
454428

455429
resource openAiRoleAssignment 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
456430
name: guid(containerAppBackend.id, openAiContributorRoleId)
457-
scope: azureAiServices
431+
scope: aiServices
458432
properties: {
459433
roleDefinitionId: subscriptionResourceId('Microsoft.Authorization/roleDefinitions', openAiContributorRoleId) // OpenAI Service Contributor
460434
principalId: containerAppBackend.identity.principalId
@@ -471,25 +445,9 @@ resource containers 'Microsoft.Storage/storageAccounts/blobServices/containers@2
471445
properties: {
472446
publicAccess: 'None'
473447
}
474-
dependsOn: [azureAifoundry]
448+
dependsOn: [aifoundry]
475449
}]
476450

477-
resource aiHubProject 'Microsoft.MachineLearningServices/workspaces@2024-01-01-preview' existing = {
478-
name: '${ResourcePrefix}-prj' // aiProjectName must be calculated - available at main start.
479-
}
480-
481-
resource aiDeveloper 'Microsoft.Authorization/roleDefinitions@2022-04-01' existing = {
482-
name: '64702f94-c441-49e6-a78b-ef80e0188fee'
483-
}
484-
485-
resource aiDeveloperAccessProj 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
486-
name: guid(containerAppBackend.name, aiHubProject.id, aiDeveloper.id)
487-
scope: aiHubProject
488-
properties: {
489-
roleDefinitionId: aiDeveloper.id
490-
principalId: containerAppBackend.identity.principalId
491-
}
492-
}
493451

494452
resource contributorRoleDefinition 'Microsoft.DocumentDB/databaseAccounts/sqlRoleDefinitions@2021-06-15' existing = {
495453
name: '${databaseAccount.name}/00000000-0000-0000-0000-000000000002'

infra/main.bicepparam

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
using './main.bicep'
22

3-
param AzureAiServiceLocation = readEnvironmentVariable('AZURE_LOCATION','japaneast')
4-
param Prefix = readEnvironmentVariable('AZURE_ENV_NAME','azdtemp')
3+
param AiLocation = readEnvironmentVariable('AZURE_LOCATION','japaneast')
4+
param ResourcePrefix = readEnvironmentVariable('AZURE_ENV_NAME','azdtemp')

0 commit comments

Comments
 (0)