Skip to content

Commit 6fc4741

Browse files
authored
Merge pull request #6 from debuggerXi/networkinjection
Add network injection support
2 parents 47c376d + 60fea2c commit 6fc4741

File tree

4 files changed

+72
-5
lines changed

4 files changed

+72
-5
lines changed

use-cases/agents/setup/standard-setup/main.bicep

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ param azureCosmosDBAccountResourceId string = ''
3939
param projectCapHost string = 'caphostproj'
4040
param accountCapHost string = 'caphostacc'
4141

42+
@allowed([
43+
'false'
44+
'true'
45+
])
46+
param enableNetworkInjection string = 'false'
47+
4248
// Create a short, unique suffix, that will be unique to each resource group
4349
param deploymentTimestamp string = utcNow('yyyyMMddHHmmss')
4450
var uniqueSuffix = substring(uniqueString('${resourceGroup().id}-${deploymentTimestamp}'), 0, 4)
@@ -67,6 +73,7 @@ var storageParts = split(azureStorageAccountResourceId, '/')
6773
var azureStorageSubscriptionId = storagePassedIn ? storageParts[2] : subscription().subscriptionId
6874
var azureStorageResourceGroupName = storagePassedIn ? storageParts[4] : resourceGroup().name
6975

76+
var virtualNetwork = toLower('${aiServices}${uniqueSuffix}vnet')
7077
/*
7178
Validate existing resources
7279
This module will check if the AI Search Service, Storage Account, and Cosmos DB Account already exist.
@@ -108,6 +115,10 @@ module aiDependencies 'modules-standard/standard-dependent-resources.bicep' = {
108115
// Cosmos DB Account
109116
cosmosDBResourceId: azureCosmosDBAccountResourceId
110117
cosmosDBExists: validateExistingResources.outputs.cosmosDBExists
118+
119+
// vnet injection
120+
vnetName: virtualNetwork
121+
networkInjection: enableNetworkInjection
111122
}
112123
}
113124

@@ -126,6 +137,9 @@ module aiAccount 'modules-standard/ai-account-identity.bicep' = {
126137
modelVersion: modelVersion
127138
modelSkuName: modelSkuName
128139
modelCapacity: modelCapacity
140+
141+
subnetId: aiDependencies.outputs.subnetId
142+
networkInjection: enableNetworkInjection
129143
}
130144
dependsOn: [
131145
validateExistingResources, aiDependencies
@@ -211,9 +225,10 @@ module addProjectCapabilityHost 'modules-standard/add-project-capability-host.bi
211225
cosmosDBConnection: aiProject.outputs.cosmosDBConnection
212226
azureStorageConnection: aiProject.outputs.azureStorageConnection
213227
aiSearchConnection: aiProject.outputs.aiSearchConnection
214-
215228
projectCapHost: projectCapHost
216229
accountCapHost: accountCapHost
230+
subnetId: aiDependencies.outputs.subnetId
231+
networkInjection: enableNetworkInjection
217232
}
218233
dependsOn: [
219234
aiSearchRoleAssignments, cosmosAccountRoleAssignments, storageAccountRoleAssignment

use-cases/agents/setup/standard-setup/modules-standard/add-project-capability-host.bicep

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ param projectName string
55
param accountName string
66
param projectCapHost string
77
param accountCapHost string
8+
param subnetId string
9+
param networkInjection string
810

911
var threadConnections = ['${cosmosDBConnection}']
1012
var storageConnections = ['${azureStorageConnection}']
@@ -15,6 +17,7 @@ var vectorStoreConnections = ['${aiSearchConnection}']
1517
resource account 'Microsoft.CognitiveServices/accounts@2025-04-01-preview' existing = {
1618
name: accountName
1719
}
20+
1821
#disable-next-line BCP081
1922
resource project 'Microsoft.CognitiveServices/accounts/projects@2025-04-01-preview' existing = {
2023
name: projectName
@@ -23,7 +26,7 @@ resource project 'Microsoft.CognitiveServices/accounts/projects@2025-04-01-previ
2326

2427

2528
#disable-next-line BCP081
26-
resource accountCapabilityHost 'Microsoft.CognitiveServices/accounts/capabilityHosts@2025-04-01-preview' = {
29+
resource accountCapabilityHost 'Microsoft.CognitiveServices/accounts/capabilityHosts@2025-04-01-preview' = if (networkInjection == 'false') {
2730
name: accountCapHost
2831
parent: account
2932
properties: {
@@ -32,7 +35,6 @@ resource project 'Microsoft.CognitiveServices/accounts/projects@2025-04-01-previ
3235
}
3336
}
3437

35-
3638
#disable-next-line BCP081
3739
resource projectCapabilityHost 'Microsoft.CognitiveServices/accounts/projects/capabilityHosts@2025-04-01-preview' = {
3840
name: projectCapHost

use-cases/agents/setup/standard-setup/modules-standard/ai-account-identity.bicep

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ param modelName string
55
param modelFormat string
66
param modelVersion string
77
param modelSkuName string
8-
param modelCapacity int
8+
param modelCapacity int
9+
param subnetId string
10+
param networkInjection string
911

1012
#disable-next-line BCP081
1113
resource account 'Microsoft.CognitiveServices/accounts@2025-04-01-preview' = {
@@ -27,7 +29,13 @@ resource account 'Microsoft.CognitiveServices/accounts@2025-04-01-preview' = {
2729
ipRules: []
2830
}
2931
publicNetworkAccess: 'Enabled'
30-
32+
networkInjections:((networkInjection == 'true') ? [
33+
{
34+
scenario: 'agent'
35+
subnetArmId: subnetId
36+
useMicrosoftManagedNetwork: false
37+
}
38+
] : [])
3139
// true is not supported today
3240
disableLocalAuth: false
3341
}

use-cases/agents/setup/standard-setup/modules-standard/standard-dependent-resources.bicep

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ param aiSearchExists bool
2929
param azureStorageExists bool
3030
param cosmosDBExists bool
3131

32+
@description('Name of the new virtual network')
33+
param vnetName string
34+
param networkInjection string
3235

3336
var cosmosParts = split(cosmosDBResourceId, '/')
3437

@@ -188,6 +191,44 @@ resource storage 'Microsoft.Storage/storageAccounts@2023-05-01' = if(!azureStora
188191
}
189192
}
190193

194+
resource virtualNetwork 'Microsoft.Network/virtualNetworks@2024-05-01' = if (networkInjection == 'true'){
195+
name: vnetName
196+
location: location
197+
properties: {
198+
addressSpace: {
199+
addressPrefixes: [
200+
'192.168.0.0/16'
201+
]
202+
}
203+
subnets: [
204+
{
205+
name: 'default'
206+
properties: {
207+
addressPrefix: '192.168.0.0/24'
208+
}
209+
}
210+
]
211+
}
212+
}
213+
214+
resource subnet 'Microsoft.Network/virtualNetworks/subnets@2024-05-01' = if (networkInjection == 'true'){
215+
parent: virtualNetwork
216+
name: 'default'
217+
properties: {
218+
addressPrefix: '192.168.0.0/24'
219+
delegations: [
220+
{
221+
id: '${virtualNetwork.id}/subnets/default"'
222+
name: 'Microsoft.App/environments'
223+
properties: {
224+
serviceName: 'Microsoft.App/environments'
225+
}
226+
type: 'Microsoft.Network/virtualNetworks/subnets/delegations'
227+
}
228+
]
229+
}
230+
}
231+
191232
// output aiServicesName string = aiServiceExists ? existingAIServiceAccount.name : aiServicesName
192233
// output aiservicesID string = aiServiceExists ? existingAIServiceAccount.id : aiServices.id
193234
// output aiservicesTarget string = aiServiceExists ? existingAIServiceAccount.properties.endpoint : aiServices.properties.endpoint
@@ -209,4 +250,5 @@ output cosmosDBId string = cosmosDBExists ? existingCosmosDB.id : cosmosDB.id
209250
output cosmosDBResourceGroupName string = cosmosDBExists ? cosmosParts[4] : resourceGroup().name
210251
output cosmosDBSubscriptionId string = cosmosDBExists ? cosmosParts[2] : subscription().subscriptionId
211252

253+
output subnetId string = subnet.id
212254
// output keyvaultId string = keyVault.id

0 commit comments

Comments
 (0)