Skip to content

Commit 6450758

Browse files
committed
happy path integration ok
1 parent 7b16473 commit 6450758

File tree

6 files changed

+159
-99
lines changed

6 files changed

+159
-99
lines changed

infra/bicep/main.bicep

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,15 @@ param acrGroupName string = ''
4444
@description('Subscription of the azure container registry.')
4545
param acrSubscription string = ''
4646

47+
@description('Enable OpenAI components')
48+
param enableOpenAi bool = false
49+
@description('Resource group of the Open AI')
50+
param openAiResourceGroup string
51+
@description('Location of the Open AI')
52+
param openAiLocation string
53+
@description('Subscription of the Open AI')
54+
param openAiSubscription string
55+
4756
@description('Name of the log analytics server. Default la-{environmentName}')
4857
param logAnalyticsName string = ''
4958

@@ -71,7 +80,7 @@ var abbrs = loadJsonContent('./abbreviations.json')
7180
var tags = { 'azd-env-name': environmentName }
7281

7382
@description('Organize resources in a resource group')
74-
resource rg 'Microsoft.Resources/resourceGroups@2021-04-01' = {
83+
resource rg 'Microsoft.Resources/resourceGroups@2024-03-01' = {
7584
name: !empty(resourceGroupName) ? resourceGroupName : '${abbrs.resourcesResourceGroups}${environmentName}'
7685
location: location
7786
tags: tags
@@ -120,6 +129,17 @@ module vnet './modules/network/vnet.bicep' = {
120129
}
121130
}
122131

132+
module mysql 'modules/database/mysql.bicep' = {
133+
name: 'mysql'
134+
scope: rg
135+
params: {
136+
administratorLogin: sqlAdmin
137+
administratorLoginPassword: sqlAdminPassword
138+
serverName: !empty(sqlServerName) ? sqlServerName : '${abbrs.sqlServers}${environmentName}'
139+
databaseName: 'petclinic'
140+
}
141+
}
142+
123143
module logAnalytics 'modules/shared/logAnalyticsWorkspace.bicep' = {
124144
name: 'log-analytics'
125145
scope: rg
@@ -188,23 +208,25 @@ module javaComponents 'modules/containerapps/containerapp-java-components.bicep'
188208
}
189209
}
190210

191-
module mysql 'modules/database/mysql.bicep' = {
192-
name: 'mysql'
193-
scope: rg
211+
// You must use modules to deploy resources to a different scope.
212+
module rgOpenAi 'modules/shared/resourceGroup.bicep' = if (enableOpenAi) {
213+
name: 'rg-openai'
214+
scope: subscription(openAiSubscription)
194215
params: {
195-
administratorLogin: sqlAdmin
196-
administratorLoginPassword: sqlAdminPassword
197-
serverName: !empty(sqlServerName) ? sqlServerName : '${abbrs.sqlServers}${environmentName}'
198-
databaseName: 'petclinic'
216+
resourceGroupName: openAiResourceGroup
217+
resourceGroupLocation: location
199218
}
200219
}
201220

202-
module openai 'modules/ai/openai.bicep' = {
221+
module openai 'modules/ai/openai.bicep' = if (enableOpenAi) {
203222
name: 'openai'
204-
scope: rg
223+
dependsOn: [
224+
rgOpenAi
225+
]
226+
scope: resourceGroup(openAiSubscription, openAiResourceGroup)
205227
params: {
206228
accountName: 'openai-${environmentName}'
207-
location: location
229+
location: openAiLocation
208230
appPrincipalId: umiApps.outputs.principalId
209231
}
210232
}
@@ -228,6 +250,7 @@ module applications 'modules/app/petclinic.bicep' = {
228250
chatAgentImage: !empty(chatAgentImage) ? chatAgentImage : placeholderImage
229251
targetPort: 8080
230252
applicationInsightsConnString: applicationInsights.outputs.connectionString
253+
enableOpenAi: enableOpenAi
231254
azureOpenAiEndpoint: openai.outputs.endpoint
232255
openAiClientId: umiApps.outputs.id
233256
}

infra/bicep/main.parameters.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,18 @@
3434
},
3535
"acrSubscription": {
3636
"value": "<your-acr-subscription>"
37+
},
38+
"enableOpenAi": {
39+
"value": true
40+
},
41+
"openAiResourceGroup": {
42+
"value": "rg-openai"
43+
},
44+
"openAiLocation": {
45+
"value": "westus"
46+
},
47+
"openAiSubscription": {
48+
"value": "<your-openai-subscription>"
3749
}
3850
}
3951
}

infra/bicep/modules/ai/openai.bicep

Lines changed: 86 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,86 @@
1-
@description('Required. Name of your Azure OpenAI service account. ')
2-
param accountName string
3-
4-
@description('Required. Location for all resources.')
5-
param location string
6-
7-
@description('Optional. model name for the TextEmbeddingAda002 language model. ')
8-
param modelTextEmbeddingAda002 string = 'text-embedding-ada-002'
9-
10-
@description('Optional. model name for the gpt-4 language model. ')
11-
param modelGpt4 string = 'gpt-4'
12-
13-
@description('Optional. model format for the language models. ')
14-
param modelFormat string = 'OpenAI'
15-
16-
@description('Required. The principal ID of the MI for the chate agent application. ')
17-
param appPrincipalId string
18-
19-
@description('Optional. The role definition ID for the Cognitive Services OpenAI User role. ')
20-
// https://learn.microsoft.com/en-us/azure/role-based-access-control/built-in-roles/ai-machine-learning#cognitive-services-openai-user
21-
param roleDefinitionId string = '5e0bd9bd-7b93-4f28-af87-19fc36ad61bd'
22-
23-
resource account 'Microsoft.CognitiveServices/accounts@2023-05-01' = {
24-
name: accountName
25-
location: location
26-
sku: {
27-
name: 'S0'
28-
}
29-
kind: 'OpenAI'
30-
properties: {
31-
customSubDomainName: accountName
32-
publicNetworkAccess: 'Enabled'
33-
disableLocalAuth: true
34-
}
35-
}
36-
37-
resource modelDeploymentTextEmbeddingAda002 'Microsoft.CognitiveServices/accounts/deployments@2023-05-01' = {
38-
name: modelTextEmbeddingAda002
39-
parent: account
40-
properties: {
41-
model: {
42-
name: modelTextEmbeddingAda002
43-
version: '2'
44-
format: modelFormat
45-
}
46-
}
47-
sku: {
48-
name: 'Standard'
49-
capacity: 1
50-
}
51-
}
52-
53-
resource modelDeploymentGpt4 'Microsoft.CognitiveServices/accounts/deployments@2023-05-01' = {
54-
name: modelGpt4
55-
parent: account
56-
properties: {
57-
model: {
58-
name: modelGpt4
59-
version: '0613'
60-
format: modelFormat
61-
}
62-
}
63-
sku: {
64-
name: 'GlobalBatch'
65-
capacity: 1
66-
}
67-
}
68-
69-
resource roleAssignment 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
70-
name: guid(resourceGroup().id, appPrincipalId, roleDefinitionId)
71-
properties: {
72-
roleDefinitionId: roleDefinitionId
73-
principalId: appPrincipalId
74-
principalType: 'ServicePrincipal'
75-
}
76-
}
77-
78-
output endpoint string = account.properties.endpoint
79-
output resourceId string = account.id
1+
targetScope = 'resourceGroup'
2+
3+
@description('Required. Name of your Azure OpenAI service account. ')
4+
param accountName string
5+
6+
@description('Required. Location for all resources.')
7+
param location string
8+
9+
@description('Optional. model name for the TextEmbeddingAda002 language model. ')
10+
param modelTextEmbeddingAda002 string = 'text-embedding-ada-002'
11+
12+
@description('Optional. model name for the gpt-4 language model. ')
13+
param modelGpt4 string = 'gpt-4'
14+
15+
@description('Optional. model format for the language models. ')
16+
param modelFormat string = 'OpenAI'
17+
18+
@description('Required. The principal ID of the MI for the chate agent application. ')
19+
param appPrincipalId string
20+
21+
@description('Optional. The role definition ID for the Cognitive Services OpenAI User role. ')
22+
// https://learn.microsoft.com/en-us/azure/role-based-access-control/built-in-roles/ai-machine-learning#cognitive-services-openai-user
23+
param roleDefinitionId string = '5e0bd9bd-7b93-4f28-af87-19fc36ad61bd'
24+
25+
resource account 'Microsoft.CognitiveServices/accounts@2023-05-01' = {
26+
name: accountName
27+
location: location
28+
sku: {
29+
name: 'S0'
30+
}
31+
kind: 'OpenAI'
32+
properties: {
33+
customSubDomainName: accountName
34+
publicNetworkAccess: 'Enabled'
35+
disableLocalAuth: true
36+
}
37+
}
38+
39+
resource modelDeploymentTextEmbeddingAda002 'Microsoft.CognitiveServices/accounts/deployments@2023-05-01' = {
40+
name: modelTextEmbeddingAda002
41+
parent: account
42+
properties: {
43+
model: {
44+
name: modelTextEmbeddingAda002
45+
version: '2'
46+
format: modelFormat
47+
}
48+
}
49+
sku: {
50+
name: 'Standard'
51+
capacity: 1
52+
}
53+
}
54+
55+
resource modelDeploymentGpt4 'Microsoft.CognitiveServices/accounts/deployments@2023-05-01' = {
56+
name: modelGpt4
57+
dependsOn: [ modelDeploymentTextEmbeddingAda002 ]
58+
parent: account
59+
properties: {
60+
model: {
61+
name: modelGpt4
62+
version: '0613'
63+
format: modelFormat
64+
}
65+
}
66+
sku: {
67+
name: 'GlobalBatch'
68+
capacity: 1
69+
}
70+
}
71+
72+
resource roleAssignment 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
73+
name: guid(resourceGroup().id, appPrincipalId, roleDefinitionId)
74+
scope: account
75+
dependsOn: [
76+
modelDeploymentGpt4
77+
modelDeploymentTextEmbeddingAda002
78+
]
79+
properties: {
80+
roleDefinitionId: resourceId('Microsoft.Authorization/roleDefinitions', roleDefinitionId)
81+
principalId: appPrincipalId
82+
}
83+
}
84+
85+
output endpoint string = account.properties.endpoint
86+
output resourceId string = account.id

infra/bicep/modules/app/petclinic.bicep

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ param adminServerImage string
1818
param chatAgentImage string
1919

2020
param applicationInsightsConnString string = ''
21+
22+
param enableOpenAi bool
23+
2124
param azureOpenAiEndpoint string
2225
param openAiClientId string
2326

@@ -145,7 +148,7 @@ module visitsService '../containerapps/containerapp.bicep' = {
145148
}
146149
}
147150

148-
module chatAgent '../containerapps/containerapp.bicep' = {
151+
module chatAgent '../containerapps/containerapp.bicep' = if (enableOpenAi) {
149152
name: 'chat-agent'
150153
params: {
151154
location: environment.location
@@ -159,7 +162,18 @@ module chatAgent '../containerapps/containerapp.bicep' = {
159162
external: true
160163
targetPort: targetPort
161164
createSqlConnection: false
162-
env: concat(env, empty(applicationInsightsConnString) ? [] : [
165+
env: concat(env,
166+
empty(applicationInsightsConnString) ? [] : [
167+
{
168+
name: 'APPLICATIONINSIGHTS_CONNECTION_STRING'
169+
value: applicationInsightsConnString
170+
}
171+
{
172+
name: 'APPLICATIONINSIGHTS_CONFIGURATION_CONTENT'
173+
value: '{"role": {"name": "chat-agent"}}'
174+
}
175+
],
176+
!enableOpenAi ? [] : [
163177
{
164178
name: 'SPRING_AI_AZURE_OPENAI_ENDPOINT'
165179
value: azureOpenAiEndpoint
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
targetScope='subscription'
2+
3+
param resourceGroupName string
4+
param resourceGroupLocation string
5+
6+
resource rg 'Microsoft.Resources/resourceGroups@2024-03-01' = {
7+
name: resourceGroupName
8+
location: resourceGroupLocation
9+
}
10+
11+
output name string = rg.name

src/pom.xml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,6 @@
7474
<version>${assertj.version}</version>
7575
<scope>test</scope>
7676
</dependency>
77-
<dependency>
78-
<groupId>com.azure.spring</groupId>
79-
<artifactId>spring-cloud-azure-dependencies</artifactId>
80-
<version>${version.spring.cloud.azure}</version>
81-
<type>pom</type>
82-
<scope>import</scope>
83-
</dependency>
8477
<dependency>
8578
<groupId>org.springframework.ai</groupId>
8679
<artifactId>spring-ai-bom</artifactId>

0 commit comments

Comments
 (0)