|
| 1 | +// ============================================================================ |
| 2 | +// Module: AI Search |
| 3 | +// Description: Deploys Azure AI Search with a two-step pattern: |
| 4 | +// Step 1: Plain Bicep resource for fast initial creation (name, location, SKU) |
| 5 | +// Step 2: AVM module update to enable managed identity & full configuration |
| 6 | +// This reduces deployment time by making the resource available immediately |
| 7 | +// while identity enablement proceeds separately. |
| 8 | +// AVM Module: avm/res/search/search-service:0.12.0 |
| 9 | +// WAF: https://learn.microsoft.com/azure/well-architected/service-guides/azure-cognitive-search |
| 10 | +// ============================================================================ |
| 11 | + |
| 12 | +@description('Solution name suffix used to derive the resource name.') |
| 13 | +@minLength(3) |
| 14 | +param solutionName string |
| 15 | + |
| 16 | +@description('Optional. Override name for the search service. Defaults to srch-{solutionName}.') |
| 17 | +param name string = 'srch-${solutionName}' |
| 18 | + |
| 19 | +@description('Azure region for the resource.') |
| 20 | +param location string |
| 21 | + |
| 22 | +@description('Tags to apply to the resource.') |
| 23 | +param tags object = {} |
| 24 | + |
| 25 | +@description('SKU name for the search service.') |
| 26 | +@allowed(['free', 'basic', 'standard', 'standard2', 'standard3', 'storage_optimized_l1', 'storage_optimized_l2']) |
| 27 | +param skuName string = 'basic' |
| 28 | + |
| 29 | +@description('Number of replicas.') |
| 30 | +param replicaCount int = 1 |
| 31 | + |
| 32 | +@description('Number of partitions.') |
| 33 | +param partitionCount int = 1 |
| 34 | + |
| 35 | +@description('Hosting mode.') |
| 36 | +@allowed(['Default', 'HighDensity']) |
| 37 | +param hostingMode string = 'Default' |
| 38 | + |
| 39 | +@description('Semantic search tier.') |
| 40 | +@allowed(['disabled', 'free', 'standard']) |
| 41 | +param semanticSearch string = 'free' |
| 42 | + |
| 43 | +@description('Whether to disable local authentication.') |
| 44 | +param disableLocalAuth bool = true |
| 45 | + |
| 46 | +@description('Managed identity type for the search service.') |
| 47 | +param managedIdentityType string = 'SystemAssigned' |
| 48 | + |
| 49 | +@description('Public network access setting.') |
| 50 | +param publicNetworkAccess string = 'Enabled' |
| 51 | + |
| 52 | +// --- WAF: Telemetry --- |
| 53 | +@description('Optional. Enable/Disable usage telemetry for module.') |
| 54 | +param enableTelemetry bool = true |
| 55 | + |
| 56 | +// --- WAF: Monitoring --- |
| 57 | +@description('Diagnostic settings for monitoring.') |
| 58 | +param diagnosticSettings array = [] |
| 59 | + |
| 60 | +// --- WAF: Private Networking --- |
| 61 | +@description('Private endpoint configurations.') |
| 62 | +param privateEndpoints array = [] |
| 63 | + |
| 64 | +// --- Role Assignments --- |
| 65 | +@description('Optional. Array of role assignments to create on the AI Search service.') |
| 66 | +param roleAssignments array = [] |
| 67 | + |
| 68 | +// ============================================================================ |
| 69 | +// Step 1: Initial resource creation (plain Bicep — fast) |
| 70 | +// ============================================================================ |
| 71 | +resource searchService 'Microsoft.Search/searchServices@2025-05-01' = { |
| 72 | + name: name |
| 73 | + location: location |
| 74 | + sku: { |
| 75 | + name: skuName |
| 76 | + } |
| 77 | +} |
| 78 | + |
| 79 | +// ============================================================================ |
| 80 | +// Step 2: AVM update — enables identity & full configuration |
| 81 | +// ============================================================================ |
| 82 | +module searchServiceUpdate 'br/public:avm/res/search/search-service:0.12.0' = { |
| 83 | + name: take('avm.res.search.update.${name}', 64) |
| 84 | + params: { |
| 85 | + name: name |
| 86 | + location: location |
| 87 | + tags: tags |
| 88 | + enableTelemetry: enableTelemetry |
| 89 | + sku: skuName |
| 90 | + replicaCount: replicaCount |
| 91 | + partitionCount: partitionCount |
| 92 | + hostingMode: hostingMode |
| 93 | + semanticSearch: semanticSearch |
| 94 | + disableLocalAuth: disableLocalAuth |
| 95 | + publicNetworkAccess: publicNetworkAccess |
| 96 | + managedIdentities: { |
| 97 | + systemAssigned: managedIdentityType == 'SystemAssigned' |
| 98 | + } |
| 99 | + diagnosticSettings: !empty(diagnosticSettings) ? diagnosticSettings : [] |
| 100 | + privateEndpoints: privateEndpoints |
| 101 | + roleAssignments: !empty(roleAssignments) ? roleAssignments : [] |
| 102 | + } |
| 103 | + dependsOn: [ |
| 104 | + searchService |
| 105 | + ] |
| 106 | +} |
| 107 | + |
| 108 | +// ============================================================================ |
| 109 | +// Outputs |
| 110 | +// ============================================================================ |
| 111 | +@description('Resource ID of the AI Search service.') |
| 112 | +output resourceId string = searchService.id |
| 113 | + |
| 114 | +@description('Name of the AI Search service.') |
| 115 | +output name string = searchService.name |
| 116 | + |
| 117 | +@description('Endpoint URL of the AI Search service.') |
| 118 | +output endpoint string = 'https://${searchService.name}.search.windows.net' |
| 119 | + |
| 120 | +@description('System-assigned identity principal ID.') |
| 121 | +output identityPrincipalId string = searchServiceUpdate.outputs.?systemAssignedMIPrincipalId ?? '' |
0 commit comments