Skip to content

Commit a99914c

Browse files
Fix the user assigned identity issue and added quota check, removed hard coded value
2 parents 240f5cf + 9d6ecbd commit a99914c

File tree

5 files changed

+29
-10
lines changed

5 files changed

+29
-10
lines changed

infra/main.bicep

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ param solutionName string = 'macae'
1717
param solutionUniqueText string = take(uniqueString(subscription().id, resourceGroup().name, solutionName), 5)
1818

1919
@metadata({ azd: { type: 'location' } })
20-
@description('Optional. Azure region for all services. Regions are restricted to guarantee compatibility with paired regions and replica locations for data redundancy and failover scenarios based on articles [Azure regions list](https://learn.microsoft.com/azure/reliability/regions-list) and [Azure Database for MySQL Flexible Server - Azure Regions](https://learn.microsoft.com/azure/mysql/flexible-server/overview#azure-regions).')
20+
@description('Required. Azure region for all services. Regions are restricted to guarantee compatibility with paired regions and replica locations for data redundancy and failover scenarios based on articles [Azure regions list](https://learn.microsoft.com/azure/reliability/regions-list) and [Azure Database for MySQL Flexible Server - Azure Regions](https://learn.microsoft.com/azure/mysql/flexible-server/overview#azure-regions).')
2121
@allowed([
2222
'australiaeast'
2323
'centralus'
@@ -30,13 +30,20 @@ param solutionUniqueText string = take(uniqueString(subscription().id, resourceG
3030
'westeurope'
3131
'uksouth'
3232
])
33-
param location string = 'australiaeast'
33+
param location string
3434

3535
// Restricting deployment to only supported Azure OpenAI regions validated with GPT-4o model
3636
@allowed(['australiaeast', 'eastus2', 'francecentral', 'japaneast', 'norwayeast', 'swedencentral', 'uksouth', 'westus'])
37-
@metadata({ azd: { type: 'location' } })
37+
@metadata({
38+
azd : {
39+
type: 'location'
40+
usageName : [
41+
'OpenAI.GlobalStandard.gpt-4o, 150'
42+
]
43+
}
44+
})
3845
@description('Optional. Location for all AI service resources. This should be one of the supported Azure AI Service locations.')
39-
param azureAiServiceLocation string = 'australiaeast'
46+
param azureAiServiceLocation string
4047

4148
@description('Optional. The tags to apply to all deployed Azure resources.')
4249
param tags resourceInput<'Microsoft.Resources/resourceGroups@2025-04-01'>.tags = {}
@@ -86,7 +93,15 @@ param enableTelemetry bool = true
8693
// Variables //
8794
// ============== //
8895

89-
var solutionSuffix = '${solutionName}${solutionUniqueText}'
96+
var solutionSuffix = toLower(trim(replace(
97+
replace(
98+
replace(replace(replace(replace('${solutionName}${solutionUniqueText}', '-', ''), '_', ''), '.', ''), '/', ''),
99+
' ',
100+
''
101+
),
102+
'*',
103+
''
104+
)))
90105

91106
// Region pairs list based on article in [Azure regions list](https://learn.microsoft.com/azure/reliability/regions-list)
92107
// var azureRegionPairs = {
@@ -1331,6 +1346,10 @@ module containerApp 'br/public:avm/res/app/container-app:0.18.1' = {
13311346
name: 'AZURE_AI_AGENT_MODEL_DEPLOYMENT_NAME'
13321347
value: aiFoundryAiServicesModelDeployment.name
13331348
}
1349+
{
1350+
name: 'AZURE_CLIENT_ID'
1351+
value: userAssignedIdentity.outputs.clientId // NOTE: This is the client ID of the managed identity, not the Entra application, and is needed for the App Service to access the Cosmos DB account.
1352+
}
13341353
]
13351354
}
13361355
]

src/backend/app_config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def get_cosmos_database_client(self):
115115
try:
116116
if self._cosmos_client is None:
117117
self._cosmos_client = CosmosClient(
118-
self.COSMOSDB_ENDPOINT, credential=get_azure_credential()
118+
self.COSMOSDB_ENDPOINT, credential=get_azure_credential(self.AZURE_CLIENT_ID)
119119
)
120120

121121
if self._cosmos_database is None:
@@ -152,7 +152,7 @@ def get_ai_project_client(self):
152152
return self._ai_project_client
153153

154154
try:
155-
credential = get_azure_credential()
155+
credential = get_azure_credential(self.AZURE_CLIENT_ID)
156156
if credential is None:
157157
raise RuntimeError(
158158
"Unable to acquire Azure credentials; ensure Managed Identity is configured"

src/backend/config_kernel.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class Config:
3232
@staticmethod
3333
def GetAzureCredentials():
3434
"""Get Azure credentials using the AppConfig implementation."""
35-
return get_azure_credential()
35+
return get_azure_credential(config.AZURE_CLIENT_ID)
3636

3737
@staticmethod
3838
def GetCosmosDatabaseClient():

src/backend/context/cosmos_memory_kernel.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ async def initialize(self):
7373
if not self._database:
7474
# Create Cosmos client
7575
cosmos_client = CosmosClient(
76-
self._cosmos_endpoint, credential=get_azure_credential()
76+
self._cosmos_endpoint, credential=get_azure_credential(config.AZURE_CLIENT_ID)
7777
)
7878
self._database = cosmos_client.get_database_client(
7979
self._cosmos_database

src/backend/utils_kernel.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ async def rai_success(description: str, is_task_creation: bool) -> bool:
172172
"""
173173
try:
174174
# Use managed identity for authentication to Azure OpenAI
175-
credential = get_azure_credential()
175+
credential = get_azure_credential(config.AZURE_CLIENT_ID)
176176
access_token = credential.get_token(
177177
"https://cognitiveservices.azure.com/.default"
178178
).token

0 commit comments

Comments
 (0)