Skip to content

Commit e5141e5

Browse files
refactor: Code refactoring
1 parent df5b326 commit e5141e5

File tree

7 files changed

+419
-1196
lines changed

7 files changed

+419
-1196
lines changed

infra/main.bicep

Lines changed: 49 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,6 @@ param azureOpenAIVisionModelCapacity int = 10
173173
'openai_function'
174174
'semantic_kernel'
175175
'langchain'
176-
'prompt_flow'
177176
])
178177
param orchestrationStrategy string = 'semantic_kernel'
179178

@@ -351,10 +350,9 @@ var blobContainerName = 'documents'
351350
var queueName = 'doc-processing'
352351
var clientKey = '${uniqueString(guid(subscription().id, deployment().name))}${newGuidString}'
353352
var eventGridSystemTopicName = 'doc-processing'
354-
// var tags = { 'azd-env-name': solutionName }
355-
var baseUrl = 'https://raw.githubusercontent.com/Azure-Samples/chat-with-your-data-solution-accelerator/waf-avm/'
353+
var baseUrl = 'https://raw.githubusercontent.com/Azure-Samples/chat-with-your-data-solution-accelerator/main/'
356354
var appversion = 'latest' // Update GIT deployment branch
357-
var registryName = 'cwydcontainerregpk' // Update Registry name
355+
var registryName = 'cwydcontainerreg' // Update Registry name
358356

359357
var openAIFunctionsSystemPrompt = '''You help employees to navigate only private information sources.
360358
You must prioritize the function call over your general knowledge for any question by calling the search_documents function.
@@ -380,8 +378,11 @@ var allTags = union(
380378
},
381379
tags
382380
)
383-
@description('Optional. The name of user who is creating this deployment.')
384-
param createdBy string = empty(deployer().userPrincipalName) ? '' : split(deployer().userPrincipalName, '@')[0]
381+
382+
@description('Optional. Created by user name.')
383+
param createdBy string = contains(deployer(), 'userPrincipalName')
384+
? split(deployer().userPrincipalName, '@')[0]
385+
: deployer().objectId
385386

386387
resource resourceGroupTags 'Microsoft.Resources/tags@2025-04-01' = {
387388
name: 'default'
@@ -391,7 +392,6 @@ resource resourceGroupTags 'Microsoft.Resources/tags@2025-04-01' = {
391392
...allTags
392393
TemplateName: 'CWYD'
393394
CreatedBy: createdBy
394-
SecurityControl: 'Ignore'
395395
}
396396
}
397397
}
@@ -456,9 +456,9 @@ module network 'modules/network.bicep' = if (enablePrivateNetworking) {
456456
params: {
457457
resourcesName: networkResourceName
458458
logAnalyticsWorkSpaceResourceId: enableMonitoring ? monitoring!.outputs.logAnalyticsWorkspaceId : ''
459-
vmAdminUsername: !empty(virtualMachineAdminUsername) ? virtualMachineAdminUsername : 'JumpboxAdminUser'
460-
vmAdminPassword: !empty(virtualMachineAdminPassword) ? virtualMachineAdminPassword : 'JumpboxAdminP@ssw0rd1234!'
461-
vmSize: vmSize ?? 'Standard_DS2_v2' // Default VM size
459+
vmAdminUsername: empty(virtualMachineAdminUsername) ? 'JumpboxAdminUser' : virtualMachineAdminUsername
460+
vmAdminPassword: empty(virtualMachineAdminPassword) ? 'JumpboxAdminP@ssw0rd1234!' : virtualMachineAdminPassword
461+
vmSize: empty(vmSize) ? 'Standard_DS2_v2' : vmSize
462462
location: location
463463
tags: allTags
464464
enableTelemetry: enableTelemetry
@@ -503,7 +503,6 @@ var dnsZoneIndex = {
503503
openAI: 7
504504
keyVault: 8
505505
machinelearning: 9
506-
// The indexes for 'storageFile' and 'containerRegistry' have been removed as they were unused
507506
}
508507

509508
// ===================================================
@@ -635,7 +634,6 @@ module postgresDBModule 'br/public:avm/res/db-for-postgre-sql/flexible-server:0.
635634
highAvailability: enableRedundancy ? 'ZoneRedundant' : 'Disabled'
636635
highAvailabilityZone: enableRedundancy ? 2 : -1
637636
publicNetworkAccess: enablePrivateNetworking ? 'Disabled' : 'Enabled'
638-
//delegatedSubnetResourceId: enablePrivateNetworking ? network!.outputs.subnetPrivateEndpointsResourceId : null
639637
privateEndpoints: enablePrivateNetworking
640638
? [
641639
{
@@ -929,7 +927,9 @@ module computerVision 'modules/core/ai/cognitiveservices.bicep' = if (useAdvance
929927
dependsOn: enablePrivateNetworking ? avmPrivateDnsZones : []
930928
}
931929

932-
var enablePrivateNetworkingSpeech = false // Speech service does not work with private endpoints in all regions, so default to false
930+
// The Web socket from front end application connects to Speech service over a public internet and it does not work over a Private endpoint.
931+
// So public access is enabled even if AVM WAF is enabled.
932+
var enablePrivateNetworkingSpeech = false
933933
module speechService 'modules/core/ai/cognitiveservices.bicep' = {
934934
name: speechServiceName
935935
scope: resourceGroup()
@@ -1011,7 +1011,6 @@ module search 'br/public:avm/res/search/search-service:0.11.1' = if (databaseTyp
10111011
{
10121012
name: 'search-dns-zone-group-blob'
10131013
privateDnsZoneResourceId: avmPrivateDnsZones[dnsZoneIndex.searchService]!.outputs.resourceId
1014-
// privateDnsZoneResourceId: avmPrivateDnsZones[dnsZoneIndex.storageBlob].outputs.resourceId.value
10151014
}
10161015
]
10171016
}
@@ -1085,7 +1084,6 @@ module webServerFarm 'br/public:avm/res/web/serverfarm:0.5.0' = {
10851084
// WAF aligned configuration for Redundancy
10861085
zoneRedundant: enableRedundancy ? true : false
10871086
}
1088-
// scope: resourceGroup()
10891087
}
10901088

10911089
var postgresDBFqdn = '${postgresResourceName}.postgres.database.azure.com'
@@ -1490,6 +1488,9 @@ module contentsafety 'modules/core/ai/cognitiveservices.bicep' = {
14901488
dependsOn: enablePrivateNetworking ? avmPrivateDnsZones : []
14911489
}
14921490

1491+
// If advanced image processing is used, storage account already should be publicly accessible.
1492+
// Computer Vision requires files to be publicly accessible as per the official docsumentation: https://learn.microsoft.com/en-us/azure/ai-services/computer-vision/how-to/blob-storage-search
1493+
var enablePrivateEndpointsStorage = enablePrivateNetworking && !useAdvancedImageProcessing
14931494
module storage './modules/storage/storage-account/storage-account.bicep' = {
14941495
name: take('avm.res.storage.storage-account.${storageAccountName}', 64)
14951496
params: {
@@ -1543,9 +1544,9 @@ module storage './modules/storage/storage-account/storage-account.bicep' = {
15431544
}
15441545
]
15451546
allowSharedKeyAccess: true
1546-
publicNetworkAccess: enablePrivateNetworking ? 'Disabled' : 'Enabled'
1547-
networkAcls: { bypass: 'AzureServices', defaultAction: enablePrivateNetworking ? 'Deny' : 'Allow' }
1548-
privateEndpoints: enablePrivateNetworking
1547+
publicNetworkAccess: enablePrivateEndpointsStorage ? 'Disabled' : 'Enabled'
1548+
networkAcls: { bypass: 'AzureServices', defaultAction: enablePrivateEndpointsStorage ? 'Deny' : 'Allow' }
1549+
privateEndpoints: enablePrivateEndpointsStorage
15491550
? [
15501551
{
15511552
name: 'pep-blob-${solutionSuffix}'
@@ -1554,7 +1555,6 @@ module storage './modules/storage/storage-account/storage-account.bicep' = {
15541555
{
15551556
name: 'storage-dns-zone-group-blob'
15561557
privateDnsZoneResourceId: avmPrivateDnsZones[dnsZoneIndex.storageBlob]!.outputs.resourceId
1557-
// privateDnsZoneResourceId: avmPrivateDnsZones[dnsZoneIndex.storageBlob].outputs.resourceId.value
15581558
}
15591559
]
15601560
}
@@ -1667,37 +1667,37 @@ var systemAssignedRoleAssignments = union(
16671667
databaseType == 'CosmosDB'
16681668
? [
16691669
{
1670-
principalId: search.outputs.systemAssignedMIPrincipalId
1671-
resourceId: storage.outputs.resourceId
1672-
roleName: 'Storage Blob Data Contributor'
1673-
roleDefinitionId: 'ba92f5b4-2d11-453d-a403-e96b0029c9fe'
1674-
principalType: 'ServicePrincipal'
1675-
}
1676-
{
1677-
principalId: search.outputs.systemAssignedMIPrincipalId
1678-
resourceId: openai.outputs.resourceId
1679-
roleName: 'Cognitive Services User'
1680-
roleDefinitionId: 'a97b65f3-24c7-4388-baec-2e87135dc908'
1681-
principalType: 'ServicePrincipal'
1682-
}
1683-
{
1684-
principalId: search.outputs.systemAssignedMIPrincipalId
1685-
resourceId: openai.outputs.resourceId
1686-
roleName: 'Cognitive Services OpenAI User'
1687-
roleDefinitionId: '5e0bd9bd-7b93-4f28-af87-19fc36ad61bd'
1688-
principalType: 'ServicePrincipal'
1689-
}
1690-
]
1670+
principalId: search.outputs.systemAssignedMIPrincipalId
1671+
resourceId: storage.outputs.resourceId
1672+
roleName: 'Storage Blob Data Contributor'
1673+
roleDefinitionId: 'ba92f5b4-2d11-453d-a403-e96b0029c9fe'
1674+
principalType: 'ServicePrincipal'
1675+
}
1676+
{
1677+
principalId: search.outputs.systemAssignedMIPrincipalId
1678+
resourceId: openai.outputs.resourceId
1679+
roleName: 'Cognitive Services User'
1680+
roleDefinitionId: 'a97b65f3-24c7-4388-baec-2e87135dc908'
1681+
principalType: 'ServicePrincipal'
1682+
}
1683+
{
1684+
principalId: search.outputs.systemAssignedMIPrincipalId
1685+
resourceId: openai.outputs.resourceId
1686+
roleName: 'Cognitive Services OpenAI User'
1687+
roleDefinitionId: '5e0bd9bd-7b93-4f28-af87-19fc36ad61bd'
1688+
principalType: 'ServicePrincipal'
1689+
}
1690+
]
16911691
: [],
1692-
[
1693-
{
1694-
principalId: formrecognizer.outputs.systemAssignedMIPrincipalId
1695-
resourceId: storage.outputs.resourceId
1696-
roleName: 'Storage Blob Data Contributor'
1697-
roleDefinitionId: 'ba92f5b4-2d11-453d-a403-e96b0029c9fe'
1698-
principalType: 'ServicePrincipal'
1699-
}
1700-
]
1692+
[
1693+
{
1694+
principalId: formrecognizer.outputs.systemAssignedMIPrincipalId
1695+
resourceId: storage.outputs.resourceId
1696+
roleName: 'Storage Blob Data Contributor'
1697+
roleDefinitionId: 'ba92f5b4-2d11-453d-a403-e96b0029c9fe'
1698+
principalType: 'ServicePrincipal'
1699+
}
1700+
]
17011701
)
17021702

17031703
@description('Role assignments applied to the system-assigned identity via AVM module. Objects can include: roleDefinitionId (req), roleName, principalType, resourceId.')

0 commit comments

Comments
 (0)