Skip to content

Commit 24f7ae1

Browse files
Merge pull request #112 from microsoft/exp-changes
feat: Implemented Reusing Log analytics workspace
2 parents dc9998a + 85721f9 commit 24f7ae1

File tree

5 files changed

+23
-2
lines changed

5 files changed

+23
-2
lines changed

docs/CustomizingAzdParameters.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,7 @@ Change the Model Capacity (choose a number based on available GPT model capacity
2323
azd env set AZURE_ENV_MODEL_CAPACITY 30
2424
```
2525

26+
Set the Log Analytics Workspace Id if you need to reuse the existing workspace which is already existing
27+
```shell
28+
azd env set AZURE_ENV_LOG_ANALYTICS_WORKSPACE_ID '<Existing Log Analytics Workspace Id>'
29+
```

docs/DeploymentGuide.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ When you start the deployment, most parameters will have **default values**, but
2929
| **Resource Prefix** | 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. | None |
3030
| **AI Location** | Location for all AI services resources. This location can be different from the resource group location | None |
3131
| **Capacity** | Configure capacity for **gpt-4o**. | 5k |
32+
| **Existing Log analytics workspace** | To reuse the existing Log analytics workspace Id. | |
3233

3334
This accelerator can be configured to use authentication.
3435

infra/deploy_ai_foundry.bicep

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@ param managedIdentityObjectId string
1111
param aiServicesEndpoint string
1212
param aiServicesKey string
1313
param aiServicesId string
14+
15+
param existingLogAnalyticsWorkspaceId string = ''
16+
17+
var useExisting = !empty(existingLogAnalyticsWorkspaceId)
18+
var existingLawResourceGroup = useExisting ? split(existingLogAnalyticsWorkspaceId, '/')[4] : ''
19+
var existingLawName = useExisting ? split(existingLogAnalyticsWorkspaceId, '/')[8] : ''
20+
1421
var abbrs = loadJsonContent('./abbreviations.json')
1522

1623
var storageName = '${abbrs.storage.storageAccount}${solutionName}'
@@ -32,7 +39,12 @@ resource keyVault 'Microsoft.KeyVault/vaults@2022-07-01' existing = {
3239
name: keyVaultName
3340
}
3441

35-
resource logAnalytics 'Microsoft.OperationalInsights/workspaces@2023-09-01' = {
42+
resource existingLogAnalyticsWorkspace 'Microsoft.OperationalInsights/workspaces@2020-08-01' existing = if (useExisting) {
43+
name: existingLawName
44+
scope: resourceGroup(existingLawResourceGroup)
45+
}
46+
47+
resource logAnalytics 'Microsoft.OperationalInsights/workspaces@2023-09-01' = if (!useExisting) {
3648
name: workspaceName
3749
location: location
3850
tags: {}
@@ -303,7 +315,7 @@ output aiProjectName string = aiHubProject.name
303315

304316
output storageAccountName string = storageNameCleaned
305317

306-
output logAnalyticsId string = logAnalytics.id
318+
output logAnalyticsId string = useExisting ? existingLogAnalyticsWorkspace.id : logAnalytics.id
307319
output storageAccountId string = storage.id
308320

309321
output projectConnectionString string = '${split(aiHubProject.properties.discoveryUrl, '/')[2]};${subscription().subscriptionId};${resourceGroup().name};${aiHubProject.name}'

infra/main.bicep

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ var safePrefix = length(Prefix) > 20 ? substring(Prefix, 0, 20) : Prefix
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+
param existingLogAnalyticsWorkspaceId string = ''
37+
3638
var uniqueId = toLower(uniqueString(subscription().id, safePrefix, resourceGroup().location))
3739
var UniquePrefix = 'cm${padLeft(take(uniqueId, 12), 12, '0')}'
3840
var ResourcePrefix = take('cm${safePrefix}${UniquePrefix}', 15)
@@ -136,6 +138,7 @@ module azureAifoundry 'deploy_ai_foundry.bicep' = {
136138
aiServicesEndpoint: azureAiServices.properties.endpoint
137139
aiServicesKey: azureAiServices.listKeys().key1
138140
aiServicesId: azureAiServices.id
141+
existingLogAnalyticsWorkspaceId: existingLogAnalyticsWorkspaceId
139142
}
140143
scope: resourceGroup(resourceGroup().name)
141144
}

infra/main.bicepparam

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

33
param AzureAiServiceLocation = readEnvironmentVariable('AZURE_LOCATION','japaneast')
44
param Prefix = readEnvironmentVariable('AZURE_ENV_NAME','azdtemp')
5+
param existingLogAnalyticsWorkspaceId = readEnvironmentVariable('AZURE_ENV_LOG_ANALYTICS_WORKSPACE_ID', '')

0 commit comments

Comments
 (0)