diff --git a/docs/CustomizingAzdParameters.md b/docs/CustomizingAzdParameters.md index ee72294..2585336 100644 --- a/docs/CustomizingAzdParameters.md +++ b/docs/CustomizingAzdParameters.md @@ -23,3 +23,7 @@ Change the Model Capacity (choose a number based on available GPT model capacity azd env set AZURE_ENV_MODEL_CAPACITY 30 ``` +Set the Log Analytics Workspace Id if you need to reuse the existing workspace which is already existing +```shell +azd env set AZURE_ENV_LOG_ANALYTICS_WORKSPACE_ID '' +``` diff --git a/docs/DeploymentGuide.md b/docs/DeploymentGuide.md index 3c61018..c0f6f1b 100644 --- a/docs/DeploymentGuide.md +++ b/docs/DeploymentGuide.md @@ -29,6 +29,7 @@ When you start the deployment, most parameters will have **default values**, but | **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 | | **AI Location** | Location for all AI services resources. This location can be different from the resource group location | None | | **Capacity** | Configure capacity for **gpt-4o**. | 5k | +| **Existing Log analytics workspace** | To reuse the existing Log analytics workspace Id. | | This accelerator can be configured to use authentication. diff --git a/infra/deploy_ai_foundry.bicep b/infra/deploy_ai_foundry.bicep index 11f49e5..72adabe 100644 --- a/infra/deploy_ai_foundry.bicep +++ b/infra/deploy_ai_foundry.bicep @@ -11,6 +11,13 @@ param managedIdentityObjectId string param aiServicesEndpoint string param aiServicesKey string param aiServicesId string + +param existingLogAnalyticsWorkspaceId string = '' + +var useExisting = !empty(existingLogAnalyticsWorkspaceId) +var existingLawResourceGroup = useExisting ? split(existingLogAnalyticsWorkspaceId, '/')[4] : '' +var existingLawName = useExisting ? split(existingLogAnalyticsWorkspaceId, '/')[8] : '' + var abbrs = loadJsonContent('./abbreviations.json') var storageName = '${abbrs.storage.storageAccount}${solutionName}' @@ -32,7 +39,12 @@ resource keyVault 'Microsoft.KeyVault/vaults@2022-07-01' existing = { name: keyVaultName } -resource logAnalytics 'Microsoft.OperationalInsights/workspaces@2023-09-01' = { +resource existingLogAnalyticsWorkspace 'Microsoft.OperationalInsights/workspaces@2020-08-01' existing = if (useExisting) { + name: existingLawName + scope: resourceGroup(existingLawResourceGroup) +} + +resource logAnalytics 'Microsoft.OperationalInsights/workspaces@2023-09-01' = if (!useExisting) { name: workspaceName location: location tags: {} @@ -303,7 +315,7 @@ output aiProjectName string = aiHubProject.name output storageAccountName string = storageNameCleaned -output logAnalyticsId string = logAnalytics.id +output logAnalyticsId string = useExisting ? existingLogAnalyticsWorkspace.id : logAnalytics.id output storageAccountId string = storage.id output projectConnectionString string = '${split(aiHubProject.properties.discoveryUrl, '/')[2]};${subscription().subscriptionId};${resourceGroup().name};${aiHubProject.name}' diff --git a/infra/main.bicep b/infra/main.bicep index 51977ce..40b02d9 100644 --- a/infra/main.bicep +++ b/infra/main.bicep @@ -33,6 +33,8 @@ var safePrefix = length(Prefix) > 20 ? substring(Prefix, 0, 20) : Prefix param AzureAiServiceLocation string // The location used for all deployed resources. This location must be in the same region as the resource group. param capacity int = 5 +param existingLogAnalyticsWorkspaceId string = '' + var uniqueId = toLower(uniqueString(subscription().id, safePrefix, resourceGroup().location)) var UniquePrefix = 'cm${padLeft(take(uniqueId, 12), 12, '0')}' var ResourcePrefix = take('cm${safePrefix}${UniquePrefix}', 15) @@ -136,6 +138,7 @@ module azureAifoundry 'deploy_ai_foundry.bicep' = { aiServicesEndpoint: azureAiServices.properties.endpoint aiServicesKey: azureAiServices.listKeys().key1 aiServicesId: azureAiServices.id + existingLogAnalyticsWorkspaceId: existingLogAnalyticsWorkspaceId } scope: resourceGroup(resourceGroup().name) } diff --git a/infra/main.bicepparam b/infra/main.bicepparam index a369041..4ca1065 100644 --- a/infra/main.bicepparam +++ b/infra/main.bicepparam @@ -2,3 +2,4 @@ using './main.bicep' param AzureAiServiceLocation = readEnvironmentVariable('AZURE_LOCATION','japaneast') param Prefix = readEnvironmentVariable('AZURE_ENV_NAME','azdtemp') +param existingLogAnalyticsWorkspaceId = readEnvironmentVariable('AZURE_ENV_LOG_ANALYTICS_WORKSPACE_ID', '')