Skip to content

Commit 53eee09

Browse files
Merge pull request #453 from microsoft/dev
feat: Implemented reusing of log analytics service
2 parents d1646f4 + 3b2bd3c commit 53eee09

File tree

6 files changed

+110
-69
lines changed

6 files changed

+110
-69
lines changed

docs/CustomizingAzdParameters.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,9 @@ Change the Embedding Deployment Capacity (choose a number based on available emb
4040

4141
```shell
4242
azd env set AZURE_ENV_EMBEDDING_MODEL_CAPACITY 80
43+
```
44+
45+
Set the Log Analytics Workspace Id if you need to reuse the existing workspace
46+
```shell
47+
azd env set AZURE_ENV_LOG_ANALYTICS_WORKSPACE_ID '<Existing Log Analytics Workspace Id>'
4348
```

docs/DeploymentGuide.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ When you start the deployment, most parameters will have **default values**, but
107107
| **GPT Model Deployment Capacity** | Configure capacity for **GPT models**. | 30k |
108108
| **Embedding Model** | Default: **text-embedding-ada-002**. | text-embedding-ada-002 |
109109
| **Embedding Model Capacity** | Set the capacity for **embedding models**. | 80k |
110+
| **Existing Log analytics workspace** | To reuse the existing Log analytics workspace Id. | |
110111

111112
</details>
112113

infra/deploy_ai_foundry.bicep

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ param gptDeploymentCapacity int
99
param embeddingModel string
1010
param embeddingDeploymentCapacity int
1111
param managedIdentityObjectId string
12+
param existingLogAnalyticsWorkspaceId string = ''
13+
1214
var abbrs = loadJsonContent('./abbreviations.json')
1315

1416
var storageName = '${abbrs.storage.storageAccount}${solutionName}-hub'
@@ -27,6 +29,11 @@ var aiProjectName = '${abbrs.ai.aiHubProject}${solutionName}'
2729
var aiProjectFriendlyName = aiProjectName
2830
var aiSearchName = '${abbrs.ai.aiSearch}${solutionName}'
2931
var workspaceName = '${abbrs.managementGovernance.logAnalyticsWorkspace}${solutionName}'
32+
33+
var useExisting = !empty(existingLogAnalyticsWorkspaceId)
34+
var existingLawResourceGroup = useExisting ? split(existingLogAnalyticsWorkspaceId, '/')[4] : ''
35+
var existingLawName = useExisting ? split(existingLogAnalyticsWorkspaceId, '/')[8] : ''
36+
3037
var aiModelDeployments = [
3138
{
3239
name: gptModelName
@@ -56,7 +63,12 @@ resource keyVault 'Microsoft.KeyVault/vaults@2022-07-01' existing = {
5663
name: keyVaultName
5764
}
5865

59-
resource logAnalytics 'Microsoft.OperationalInsights/workspaces@2023-09-01' = {
66+
resource existingLogAnalyticsWorkspace 'Microsoft.OperationalInsights/workspaces@2020-08-01' existing = if (useExisting) {
67+
name: existingLawName
68+
scope: resourceGroup(existingLawResourceGroup)
69+
}
70+
71+
resource logAnalytics 'Microsoft.OperationalInsights/workspaces@2023-09-01' = if (!useExisting) {
6072
name: workspaceName
6173
location: location
6274
tags: {}
@@ -96,7 +108,7 @@ resource applicationInsights 'Microsoft.Insights/components@2020-02-02' = {
96108
Application_Type: 'web'
97109
publicNetworkAccessForIngestion: 'Enabled'
98110
publicNetworkAccessForQuery: 'Enabled'
99-
WorkspaceResourceId: logAnalytics.id
111+
WorkspaceResourceId: useExisting ? existingLogAnalyticsWorkspace.id : logAnalytics.id
100112
}
101113
}
102114

@@ -483,7 +495,7 @@ output aiSearchService string = aiSearch.name
483495
output aiProjectName string = aiHubProject.name
484496

485497
output applicationInsightsId string = applicationInsights.id
486-
output logAnalyticsWorkspaceResourceName string = logAnalytics.name
498+
output logAnalyticsWorkspaceResourceName string = useExisting ? existingLogAnalyticsWorkspace.name : logAnalytics.name
487499
output storageAccountName string = storageNameCleaned
488500
output applicationInsightsConnectionString string = applicationInsights.properties.ConnectionString
489501

infra/main.bicep

Lines changed: 41 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,24 @@ param embeddingDeploymentCapacity int = 80
5555

5656
param imageTag string = 'latest'
5757
param AZURE_LOCATION string=''
58+
59+
@description('Optional: Existing Log Analytics Workspace Resource ID')
60+
param existingLogAnalyticsWorkspaceId string = ''
61+
5862
var solutionLocation = empty(AZURE_LOCATION) ? resourceGroup().location : AZURE_LOCATION
5963

6064
var uniqueId = toLower(uniqueString(environmentName, subscription().id, solutionLocation))
6165
var solutionPrefix = 'dg${padLeft(take(uniqueId, 12), 12, '0')}'
6266

63-
var baseUrl = 'https://raw.githubusercontent.com/microsoft/document-generation-solution-accelerator/main/'
67+
// var baseUrl = 'https://raw.githubusercontent.com/microsoft/document-generation-solution-accelerator/main/'
68+
69+
// var ApplicationInsightsName ='${abbrs.managementGovernance.applicationInsights}${solutionPrefix}'
70+
// var WorkspaceName = '${abbrs.managementGovernance.logAnalyticsWorkspace}${solutionPrefix}'
71+
72+
// var useExisting = !empty(existingLogAnalyticsWorkspaceId)
73+
// var existingLawResourceGroup = useExisting ? split(existingLogAnalyticsWorkspaceId, '/')[4] : ''
74+
// var existingLawName = useExisting ? split(existingLogAnalyticsWorkspaceId, '/')[8] : ''
6475

65-
var ApplicationInsightsName ='${abbrs.managementGovernance.applicationInsights}${solutionPrefix}'
66-
var WorkspaceName = '${abbrs.managementGovernance.logAnalyticsWorkspace}${solutionPrefix}'
6776

6877
// ========== Managed Identity ========== //
6978
module managedIdentityModule 'deploy_managed_identity.bicep' = {
@@ -101,7 +110,8 @@ module aifoundry 'deploy_ai_foundry.bicep' = {
101110
gptDeploymentCapacity: gptDeploymentCapacity
102111
embeddingModel: embeddingModel
103112
embeddingDeploymentCapacity: embeddingDeploymentCapacity
104-
managedIdentityObjectId:managedIdentityModule.outputs.managedIdentityOutput.objectId
113+
managedIdentityObjectId: managedIdentityModule.outputs.managedIdentityOutput.objectId
114+
existingLogAnalyticsWorkspaceId: existingLogAnalyticsWorkspaceId
105115
}
106116
scope: resourceGroup(resourceGroup().name)
107117
}
@@ -396,29 +406,34 @@ module appserviceModule 'deploy_app_service.bicep' = {
396406

397407
output WEB_APP_URL string = appserviceModule.outputs.webAppUrl
398408

399-
resource Workspace 'Microsoft.OperationalInsights/workspaces@2020-08-01' = {
400-
name: WorkspaceName
401-
location: solutionLocation
402-
properties: {
403-
sku: {
404-
name: 'PerGB2018'
405-
}
406-
retentionInDays: 30
407-
}
408-
}
409+
// resource existingWorkspace 'Microsoft.OperationalInsights/workspaces@2020-08-01' existing = if (useExisting) {
410+
// name: existingLawName
411+
// scope: resourceGroup(existingLawResourceGroup)
412+
// }
409413

410-
resource ApplicationInsights 'Microsoft.Insights/components@2020-02-02' = {
411-
name: ApplicationInsightsName
412-
location: solutionLocation
413-
tags: {
414-
'hidden-link:${resourceId('Microsoft.Web/sites',ApplicationInsightsName)}': 'Resource'
415-
}
416-
properties: {
417-
Application_Type: 'web'
418-
WorkspaceResourceId: Workspace.id
419-
}
420-
kind: 'web'
421-
}
414+
// resource Workspace 'Microsoft.OperationalInsights/workspaces@2020-08-01' = if (!useExisting) {
415+
// name: WorkspaceName
416+
// location: solutionLocation
417+
// properties: {
418+
// sku: {
419+
// name: 'PerGB2018'
420+
// }
421+
// retentionInDays: 30
422+
// }
423+
// }
424+
425+
// resource ApplicationInsights 'Microsoft.Insights/components@2020-02-02' = {
426+
// name: ApplicationInsightsName
427+
// location: solutionLocation
428+
// tags: {
429+
// 'hidden-link:${resourceId('Microsoft.Web/sites',ApplicationInsightsName)}': 'Resource'
430+
// }
431+
// properties: {
432+
// Application_Type: 'web'
433+
// WorkspaceResourceId: useExisting ? existingWorkspace.id : Workspace.id
434+
// }
435+
// kind: 'web'
436+
// }
422437

423438

424439
// ========== Cosmos DB module ========== //

infra/main.bicepparam

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ param gptModelName = readEnvironmentVariable('AZURE_ENV_MODEL_NAME', 'gpt-4o')
88
param gptDeploymentCapacity = int(readEnvironmentVariable('AZURE_ENV_MODEL_CAPACITY', '30'))
99

1010
param embeddingDeploymentCapacity = int(readEnvironmentVariable('AZURE_ENV_EMBEDDING_MODEL_CAPACITY', '80'))
11+
param existingLogAnalyticsWorkspaceId = readEnvironmentVariable('AZURE_ENV_LOG_ANALYTICS_WORKSPACE_ID', '')

infra/main.json

Lines changed: 47 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"_generator": {
66
"name": "bicep",
77
"version": "0.35.1.17967",
8-
"templateHash": "13536585236097147854"
8+
"templateHash": "6972576500861957783"
99
}
1010
},
1111
"parameters": {
@@ -89,6 +89,13 @@
8989
"AZURE_LOCATION": {
9090
"type": "string",
9191
"defaultValue": ""
92+
},
93+
"existingLogAnalyticsWorkspaceId": {
94+
"type": "string",
95+
"defaultValue": "",
96+
"metadata": {
97+
"description": "Optional: Existing Log Analytics Workspace Resource ID"
98+
}
9299
}
93100
},
94101
"variables": {
@@ -322,41 +329,9 @@
322329
"abbrs": "[variables('$fxv#0')]",
323330
"solutionLocation": "[if(empty(parameters('AZURE_LOCATION')), resourceGroup().location, parameters('AZURE_LOCATION'))]",
324331
"uniqueId": "[toLower(uniqueString(parameters('environmentName'), subscription().id, variables('solutionLocation')))]",
325-
"solutionPrefix": "[format('dg{0}', padLeft(take(variables('uniqueId'), 12), 12, '0'))]",
326-
"baseUrl": "https://raw.githubusercontent.com/microsoft/document-generation-solution-accelerator/main/",
327-
"ApplicationInsightsName": "[format('{0}{1}', variables('abbrs').managementGovernance.applicationInsights, variables('solutionPrefix'))]",
328-
"WorkspaceName": "[format('{0}{1}', variables('abbrs').managementGovernance.logAnalyticsWorkspace, variables('solutionPrefix'))]"
332+
"solutionPrefix": "[format('dg{0}', padLeft(take(variables('uniqueId'), 12), 12, '0'))]"
329333
},
330334
"resources": [
331-
{
332-
"type": "Microsoft.OperationalInsights/workspaces",
333-
"apiVersion": "2020-08-01",
334-
"name": "[variables('WorkspaceName')]",
335-
"location": "[variables('solutionLocation')]",
336-
"properties": {
337-
"sku": {
338-
"name": "PerGB2018"
339-
},
340-
"retentionInDays": 30
341-
}
342-
},
343-
{
344-
"type": "Microsoft.Insights/components",
345-
"apiVersion": "2020-02-02",
346-
"name": "[variables('ApplicationInsightsName')]",
347-
"location": "[variables('solutionLocation')]",
348-
"tags": {
349-
"[format('hidden-link:{0}', resourceId('Microsoft.Web/sites', variables('ApplicationInsightsName')))]": "Resource"
350-
},
351-
"properties": {
352-
"Application_Type": "web",
353-
"WorkspaceResourceId": "[resourceId('Microsoft.OperationalInsights/workspaces', variables('WorkspaceName'))]"
354-
},
355-
"kind": "web",
356-
"dependsOn": [
357-
"[resourceId('Microsoft.OperationalInsights/workspaces', variables('WorkspaceName'))]"
358-
]
359-
},
360335
{
361336
"type": "Microsoft.Resources/deployments",
362337
"apiVersion": "2022-09-01",
@@ -610,6 +585,9 @@
610585
},
611586
"managedIdentityObjectId": {
612587
"value": "[reference(extensionResourceId(format('/subscriptions/{0}/resourceGroups/{1}', subscription().subscriptionId, resourceGroup().name), 'Microsoft.Resources/deployments', 'deploy_managed_identity'), '2022-09-01').outputs.managedIdentityOutput.value.objectId]"
588+
},
589+
"existingLogAnalyticsWorkspaceId": {
590+
"value": "[parameters('existingLogAnalyticsWorkspaceId')]"
613591
}
614592
},
615593
"template": {
@@ -619,7 +597,7 @@
619597
"_generator": {
620598
"name": "bicep",
621599
"version": "0.35.1.17967",
622-
"templateHash": "6302547316976018886"
600+
"templateHash": "10562656740645209068"
623601
}
624602
},
625603
"parameters": {
@@ -652,6 +630,10 @@
652630
},
653631
"managedIdentityObjectId": {
654632
"type": "string"
633+
},
634+
"existingLogAnalyticsWorkspaceId": {
635+
"type": "string",
636+
"defaultValue": ""
655637
}
656638
},
657639
"variables": {
@@ -897,6 +879,9 @@
897879
"aiProjectFriendlyName": "[variables('aiProjectName')]",
898880
"aiSearchName": "[format('{0}{1}', variables('abbrs').ai.aiSearch, parameters('solutionName'))]",
899881
"workspaceName": "[format('{0}{1}', variables('abbrs').managementGovernance.logAnalyticsWorkspace, parameters('solutionName'))]",
882+
"useExisting": "[not(empty(parameters('existingLogAnalyticsWorkspaceId')))]",
883+
"existingLawResourceGroup": "[if(variables('useExisting'), split(parameters('existingLogAnalyticsWorkspaceId'), '/')[4], '')]",
884+
"existingLawName": "[if(variables('useExisting'), split(parameters('existingLogAnalyticsWorkspaceId'), '/')[8], '')]",
900885
"aiModelDeployments": [
901886
{
902887
"name": "[parameters('gptModelName')]",
@@ -905,6 +890,7 @@
905890
"name": "[parameters('deploymentType')]",
906891
"capacity": "[parameters('gptDeploymentCapacity')]"
907892
},
893+
"version": "2024-05-13",
908894
"raiPolicyName": "Microsoft.Default"
909895
},
910896
{
@@ -914,6 +900,7 @@
914900
"name": "Standard",
915901
"capacity": "[parameters('embeddingDeploymentCapacity')]"
916902
},
903+
"version": "2",
917904
"raiPolicyName": "Microsoft.Default"
918905
}
919906
],
@@ -971,6 +958,7 @@
971958
]
972959
},
973960
{
961+
"condition": "[not(variables('useExisting'))]",
974962
"type": "Microsoft.OperationalInsights/workspaces",
975963
"apiVersion": "2023-09-01",
976964
"name": "[variables('workspaceName')]",
@@ -993,7 +981,7 @@
993981
"Application_Type": "web",
994982
"publicNetworkAccessForIngestion": "Enabled",
995983
"publicNetworkAccessForQuery": "Enabled",
996-
"WorkspaceResourceId": "[resourceId('Microsoft.OperationalInsights/workspaces', variables('workspaceName'))]"
984+
"WorkspaceResourceId": "[if(variables('useExisting'), extensionResourceId(format('/subscriptions/{0}/resourceGroups/{1}', subscription().subscriptionId, variables('existingLawResourceGroup')), 'Microsoft.OperationalInsights/workspaces', variables('existingLawName')), resourceId('Microsoft.OperationalInsights/workspaces', variables('workspaceName')))]"
997985
},
998986
"dependsOn": [
999987
"[resourceId('Microsoft.OperationalInsights/workspaces', variables('workspaceName'))]"
@@ -1059,9 +1047,11 @@
10591047
"properties": {
10601048
"model": {
10611049
"format": "OpenAI",
1062-
"name": "[variables('aiModelDeployments')[copyIndex()].model]"
1050+
"name": "[variables('aiModelDeployments')[copyIndex()].model]",
1051+
"version": "[variables('aiModelDeployments')[copyIndex()].version]"
10631052
},
1064-
"raiPolicyName": "[variables('aiModelDeployments')[copyIndex()].raiPolicyName]"
1053+
"raiPolicyName": "[variables('aiModelDeployments')[copyIndex()].raiPolicyName]",
1054+
"versionUpgradeOption": "OnceCurrentVersionExpired"
10651055
},
10661056
"sku": {
10671057
"name": "[variables('aiModelDeployments')[copyIndex()].sku.name]",
@@ -1399,11 +1389,15 @@
13991389
},
14001390
"logAnalyticsWorkspaceResourceName": {
14011391
"type": "string",
1402-
"value": "[variables('workspaceName')]"
1392+
"value": "[if(variables('useExisting'), variables('existingLawName'), variables('workspaceName'))]"
14031393
},
14041394
"storageAccountName": {
14051395
"type": "string",
14061396
"value": "[variables('storageNameCleaned')]"
1397+
},
1398+
"applicationInsightsConnectionString": {
1399+
"type": "string",
1400+
"value": "[reference(resourceId('Microsoft.Insights/components', variables('applicationInsightsName')), '2020-02-02').ConnectionString]"
14071401
}
14081402
}
14091403
}
@@ -1667,6 +1661,9 @@
16671661
"AZURE_COSMOSDB_DATABASE": {
16681662
"value": "[reference(extensionResourceId(format('/subscriptions/{0}/resourceGroups/{1}', subscription().subscriptionId, resourceGroup().name), 'Microsoft.Resources/deployments', 'deploy_cosmos_db'), '2022-09-01').outputs.cosmosDatabaseName.value]"
16691663
},
1664+
"appInsightsConnectionString": {
1665+
"value": "[reference(extensionResourceId(format('/subscriptions/{0}/resourceGroups/{1}', subscription().subscriptionId, resourceGroup().name), 'Microsoft.Resources/deployments', 'deploy_ai_foundry'), '2022-09-01').outputs.applicationInsightsConnectionString.value]"
1666+
},
16701667
"AZURE_COSMOSDB_ENABLE_FEEDBACK": {
16711668
"value": "True"
16721669
},
@@ -1684,7 +1681,7 @@
16841681
"_generator": {
16851682
"name": "bicep",
16861683
"version": "0.35.1.17967",
1687-
"templateHash": "2607460382594511507"
1684+
"templateHash": "16988932665267526316"
16881685
}
16891686
},
16901687
"parameters": {
@@ -1907,6 +1904,12 @@
19071904
},
19081905
"applicationInsightsId": {
19091906
"type": "string"
1907+
},
1908+
"appInsightsConnectionString": {
1909+
"type": "securestring",
1910+
"metadata": {
1911+
"description": "The Application Insights connection string"
1912+
}
19101913
}
19111914
},
19121915
"variables": {
@@ -1971,6 +1974,10 @@
19711974
"name": "APPINSIGHTS_INSTRUMENTATIONKEY",
19721975
"value": "[reference(parameters('applicationInsightsId'), '2015-05-01').InstrumentationKey]"
19731976
},
1977+
{
1978+
"name": "APPLICATIONINSIGHTS_CONNECTION_STRING",
1979+
"value": "[parameters('appInsightsConnectionString')]"
1980+
},
19741981
{
19751982
"name": "AZURE_SEARCH_SERVICE",
19761983
"value": "[parameters('aiSearchService')]"

0 commit comments

Comments
 (0)