|
1 | 1 | /* |
| 2 | +Connections enable your AI applications to access tools and objects managed elsewhere in or outside of Azure. |
| 3 | +
|
2 | 4 | This example demonstrates how to add an Azure AI Search connection. |
3 | 5 | */ |
4 | | -param aiFoundryName string = 'your-account' |
5 | | -param aiSearchName string = 'ais-${aiFoundryName}' |
| 6 | +param aiFoundryName string = '<your-account-name>' |
| 7 | +param connectedResourceName string = 'ais-${aiFoundryName}' |
| 8 | +param location string = 'westus' |
6 | 9 |
|
7 | | -// whether ai Search is existing or new |
| 10 | +// Whether to create a new Azure AI Search resource |
8 | 11 | @allowed([ |
9 | 12 | 'new' |
10 | 13 | 'existing' |
11 | 14 | ]) |
12 | 15 | param newOrExisting string = 'new' |
13 | 16 |
|
14 | | -#disable-next-line BCP081 |
| 17 | +// Refers your existing Azure AI Foundry resource |
15 | 18 | resource aiFoundry 'Microsoft.CognitiveServices/accounts@2025-04-01-preview' existing = { |
16 | 19 | name: aiFoundryName |
17 | 20 | scope: resourceGroup() |
18 | 21 | } |
19 | 22 |
|
| 23 | +// Conditionally refers your existing Azure AI Search resource |
20 | 24 | resource existingSearchService 'Microsoft.Search/searchServices@2025-02-01-preview' existing = if (newOrExisting == 'existing') { |
21 | | - name: aiSearchName |
| 25 | + name: connectedResourceName |
22 | 26 | } |
23 | 27 |
|
| 28 | +// Conditionally creates a new Azure AI Search resource |
24 | 29 | resource newSearchService 'Microsoft.Search/searchServices@2025-02-01-preview' = if (newOrExisting == 'new') { |
25 | | - name: aiSearchName |
26 | | - location: 'westus' |
| 30 | + name: connectedResourceName |
| 31 | + location: location |
27 | 32 | sku: { |
28 | 33 | name: 'basic' |
29 | 34 | } |
30 | 35 | properties: {} |
31 | 36 | } |
32 | 37 |
|
33 | | -resource project_connection_azureai_search 'Microsoft.CognitiveServices/accounts/connections@2025-04-01-preview' = { |
34 | | - name: aiSearchName |
| 38 | +// Creates the Azure Foundry connection to your Azure AI Search resource |
| 39 | +resource connection 'Microsoft.CognitiveServices/accounts/connections@2025-04-01-preview' = { |
| 40 | + name: '${aiFoundryName}-aisearch' |
35 | 41 | parent: aiFoundry |
36 | 42 | properties: { |
37 | 43 | category: 'CognitiveSearch' |
38 | 44 | target: ((newOrExisting == 'new') ? newSearchService.properties.endpoint : existingSearchService.properties.endpoint) |
39 | | - authType: 'ApiKey' |
40 | | - isSharedToAll: true |
| 45 | + authType: 'ApiKey' // Supported auth types: ApiKey, AAD |
41 | 46 | credentials: { |
42 | | - key: ((newOrExisting == 'new') ? listKeys(newSearchService.id, '2020-06-10').key1 : listKeys(existingSearchService.id, '2020-06-10').key1) |
| 47 | + key: ((newOrExisting == 'new') ? newSearchService.listAdminKeys().primaryKey : existingSearchService.listAdminKeys().primaryKey) |
43 | 48 | } |
44 | 49 | metadata: { |
45 | 50 | ApiType: 'Azure' |
|
0 commit comments