|
| 1 | +@description('Required. The name of Cognitive Services account.') |
| 2 | +param name string |
| 3 | + |
| 4 | +@description('Optional. SKU of the Cognitive Services account. Use \'Get-AzCognitiveServicesAccountSku\' to determine a valid combinations of \'kind\' and \'SKU\' for your Azure region.') |
| 5 | +@allowed([ |
| 6 | + 'C2' |
| 7 | + 'C3' |
| 8 | + 'C4' |
| 9 | + 'F0' |
| 10 | + 'F1' |
| 11 | + 'S' |
| 12 | + 'S0' |
| 13 | + 'S1' |
| 14 | + 'S10' |
| 15 | + 'S2' |
| 16 | + 'S3' |
| 17 | + 'S4' |
| 18 | + 'S5' |
| 19 | + 'S6' |
| 20 | + 'S7' |
| 21 | + 'S8' |
| 22 | + 'S9' |
| 23 | +]) |
| 24 | +param sku string = 'S0' |
| 25 | + |
| 26 | +import { deploymentType } from 'br:mcr.microsoft.com/bicep/avm/res/cognitive-services/account:0.13.2' |
| 27 | +@description('Optional. Array of deployments about cognitive service accounts to create.') |
| 28 | +param deployments deploymentType[]? |
| 29 | + |
| 30 | +import { roleAssignmentType } from 'br/public:avm/utl/types/avm-common-types:0.5.1' |
| 31 | +@description('Optional. Array of role assignments to create.') |
| 32 | +param roleAssignments roleAssignmentType[]? |
| 33 | + |
| 34 | +var builtInRoleNames = { |
| 35 | + 'Cognitive Services Contributor': subscriptionResourceId( |
| 36 | + 'Microsoft.Authorization/roleDefinitions', |
| 37 | + '25fbc0a9-bd7c-42a3-aa1a-3b75d497ee68' |
| 38 | + ) |
| 39 | + 'Cognitive Services Custom Vision Contributor': subscriptionResourceId( |
| 40 | + 'Microsoft.Authorization/roleDefinitions', |
| 41 | + 'c1ff6cc2-c111-46fe-8896-e0ef812ad9f3' |
| 42 | + ) |
| 43 | + 'Cognitive Services Custom Vision Deployment': subscriptionResourceId( |
| 44 | + 'Microsoft.Authorization/roleDefinitions', |
| 45 | + '5c4089e1-6d96-4d2f-b296-c1bc7137275f' |
| 46 | + ) |
| 47 | + 'Cognitive Services Custom Vision Labeler': subscriptionResourceId( |
| 48 | + 'Microsoft.Authorization/roleDefinitions', |
| 49 | + '88424f51-ebe7-446f-bc41-7fa16989e96c' |
| 50 | + ) |
| 51 | + 'Cognitive Services Custom Vision Reader': subscriptionResourceId( |
| 52 | + 'Microsoft.Authorization/roleDefinitions', |
| 53 | + '93586559-c37d-4a6b-ba08-b9f0940c2d73' |
| 54 | + ) |
| 55 | + 'Cognitive Services Custom Vision Trainer': subscriptionResourceId( |
| 56 | + 'Microsoft.Authorization/roleDefinitions', |
| 57 | + '0a5ae4ab-0d65-4eeb-be61-29fc9b54394b' |
| 58 | + ) |
| 59 | + 'Cognitive Services Data Reader (Preview)': subscriptionResourceId( |
| 60 | + 'Microsoft.Authorization/roleDefinitions', |
| 61 | + 'b59867f0-fa02-499b-be73-45a86b5b3e1c' |
| 62 | + ) |
| 63 | + 'Cognitive Services Face Recognizer': subscriptionResourceId( |
| 64 | + 'Microsoft.Authorization/roleDefinitions', |
| 65 | + '9894cab4-e18a-44aa-828b-cb588cd6f2d7' |
| 66 | + ) |
| 67 | + 'Cognitive Services Immersive Reader User': subscriptionResourceId( |
| 68 | + 'Microsoft.Authorization/roleDefinitions', |
| 69 | + 'b2de6794-95db-4659-8781-7e080d3f2b9d' |
| 70 | + ) |
| 71 | + 'Cognitive Services Language Owner': subscriptionResourceId( |
| 72 | + 'Microsoft.Authorization/roleDefinitions', |
| 73 | + 'f07febfe-79bc-46b1-8b37-790e26e6e498' |
| 74 | + ) |
| 75 | + 'Cognitive Services Language Reader': subscriptionResourceId( |
| 76 | + 'Microsoft.Authorization/roleDefinitions', |
| 77 | + '7628b7b8-a8b2-4cdc-b46f-e9b35248918e' |
| 78 | + ) |
| 79 | + 'Cognitive Services Language Writer': subscriptionResourceId( |
| 80 | + 'Microsoft.Authorization/roleDefinitions', |
| 81 | + 'f2310ca1-dc64-4889-bb49-c8e0fa3d47a8' |
| 82 | + ) |
| 83 | + 'Cognitive Services LUIS Owner': subscriptionResourceId( |
| 84 | + 'Microsoft.Authorization/roleDefinitions', |
| 85 | + 'f72c8140-2111-481c-87ff-72b910f6e3f8' |
| 86 | + ) |
| 87 | + 'Cognitive Services LUIS Reader': subscriptionResourceId( |
| 88 | + 'Microsoft.Authorization/roleDefinitions', |
| 89 | + '18e81cdc-4e98-4e29-a639-e7d10c5a6226' |
| 90 | + ) |
| 91 | + 'Cognitive Services LUIS Writer': subscriptionResourceId( |
| 92 | + 'Microsoft.Authorization/roleDefinitions', |
| 93 | + '6322a993-d5c9-4bed-b113-e49bbea25b27' |
| 94 | + ) |
| 95 | + 'Cognitive Services Metrics Advisor Administrator': subscriptionResourceId( |
| 96 | + 'Microsoft.Authorization/roleDefinitions', |
| 97 | + 'cb43c632-a144-4ec5-977c-e80c4affc34a' |
| 98 | + ) |
| 99 | + 'Cognitive Services Metrics Advisor User': subscriptionResourceId( |
| 100 | + 'Microsoft.Authorization/roleDefinitions', |
| 101 | + '3b20f47b-3825-43cb-8114-4bd2201156a8' |
| 102 | + ) |
| 103 | + 'Cognitive Services OpenAI Contributor': subscriptionResourceId( |
| 104 | + 'Microsoft.Authorization/roleDefinitions', |
| 105 | + 'a001fd3d-188f-4b5d-821b-7da978bf7442' |
| 106 | + ) |
| 107 | + 'Cognitive Services OpenAI User': subscriptionResourceId( |
| 108 | + 'Microsoft.Authorization/roleDefinitions', |
| 109 | + '5e0bd9bd-7b93-4f28-af87-19fc36ad61bd' |
| 110 | + ) |
| 111 | + 'Cognitive Services QnA Maker Editor': subscriptionResourceId( |
| 112 | + 'Microsoft.Authorization/roleDefinitions', |
| 113 | + 'f4cc2bf9-21be-47a1-bdf1-5c5804381025' |
| 114 | + ) |
| 115 | + 'Cognitive Services QnA Maker Reader': subscriptionResourceId( |
| 116 | + 'Microsoft.Authorization/roleDefinitions', |
| 117 | + '466ccd10-b268-4a11-b098-b4849f024126' |
| 118 | + ) |
| 119 | + 'Cognitive Services Speech Contributor': subscriptionResourceId( |
| 120 | + 'Microsoft.Authorization/roleDefinitions', |
| 121 | + '0e75ca1e-0464-4b4d-8b93-68208a576181' |
| 122 | + ) |
| 123 | + 'Cognitive Services Speech User': subscriptionResourceId( |
| 124 | + 'Microsoft.Authorization/roleDefinitions', |
| 125 | + 'f2dc8367-1007-4938-bd23-fe263f013447' |
| 126 | + ) |
| 127 | + 'Cognitive Services User': subscriptionResourceId( |
| 128 | + 'Microsoft.Authorization/roleDefinitions', |
| 129 | + 'a97b65f3-24c7-4388-baec-2e87135dc908' |
| 130 | + ) |
| 131 | + 'Azure AI Developer': subscriptionResourceId( |
| 132 | + 'Microsoft.Authorization/roleDefinitions', |
| 133 | + '64702f94-c441-49e6-a78b-ef80e0188fee' |
| 134 | + ) |
| 135 | + Contributor: subscriptionResourceId('Microsoft.Authorization/roleDefinitions', 'b24988ac-6180-42a0-ab88-20f7382dd24c') |
| 136 | + Owner: subscriptionResourceId('Microsoft.Authorization/roleDefinitions', '8e3af657-a8ff-443c-a75c-2fe8c4bcb635') |
| 137 | + Reader: subscriptionResourceId('Microsoft.Authorization/roleDefinitions', 'acdd72a7-3385-48ef-bd42-f606fba81ae7') |
| 138 | + 'Role Based Access Control Administrator': subscriptionResourceId( |
| 139 | + 'Microsoft.Authorization/roleDefinitions', |
| 140 | + 'f58310d9-a9f6-439a-9e8d-f62e7b41a168' |
| 141 | + ) |
| 142 | + 'User Access Administrator': subscriptionResourceId( |
| 143 | + 'Microsoft.Authorization/roleDefinitions', |
| 144 | + '18d7d88d-d35e-4fb5-a5c3-7773c20a72d9' |
| 145 | + ) |
| 146 | +} |
| 147 | + |
| 148 | +var formattedRoleAssignments = [ |
| 149 | + for (roleAssignment, index) in (roleAssignments ?? []): union(roleAssignment, { |
| 150 | + roleDefinitionId: builtInRoleNames[?roleAssignment.roleDefinitionIdOrName] ?? (contains( |
| 151 | + roleAssignment.roleDefinitionIdOrName, |
| 152 | + '/providers/Microsoft.Authorization/roleDefinitions/' |
| 153 | + ) |
| 154 | + ? roleAssignment.roleDefinitionIdOrName |
| 155 | + : subscriptionResourceId('Microsoft.Authorization/roleDefinitions', roleAssignment.roleDefinitionIdOrName)) |
| 156 | + }) |
| 157 | +] |
| 158 | + |
| 159 | +resource cognitiveService 'Microsoft.CognitiveServices/accounts@2025-06-01' existing = { |
| 160 | + name: name |
| 161 | +} |
| 162 | + |
| 163 | +@batchSize(1) |
| 164 | +resource cognitiveService_deployments 'Microsoft.CognitiveServices/accounts/deployments@2024-10-01' = [ |
| 165 | + for (deployment, index) in (deployments ?? []): { |
| 166 | + parent: cognitiveService |
| 167 | + name: deployment.?name ?? '${name}-deployments' |
| 168 | + properties: { |
| 169 | + model: deployment.model |
| 170 | + raiPolicyName: deployment.?raiPolicyName |
| 171 | + versionUpgradeOption: deployment.?versionUpgradeOption |
| 172 | + } |
| 173 | + sku: deployment.?sku ?? { |
| 174 | + name: sku |
| 175 | + capacity: sku.?capacity |
| 176 | + tier: sku.?tier |
| 177 | + size: sku.?size |
| 178 | + family: sku.?family |
| 179 | + } |
| 180 | + } |
| 181 | +] |
| 182 | + |
| 183 | +resource cognitiveService_roleAssignments 'Microsoft.Authorization/roleAssignments@2022-04-01' = [ |
| 184 | + for (roleAssignment, index) in (formattedRoleAssignments ?? []): { |
| 185 | + name: roleAssignment.?name ?? guid(cognitiveService.id, roleAssignment.principalId, roleAssignment.roleDefinitionId) |
| 186 | + properties: { |
| 187 | + roleDefinitionId: roleAssignment.roleDefinitionId |
| 188 | + principalId: roleAssignment.principalId |
| 189 | + description: roleAssignment.?description |
| 190 | + principalType: roleAssignment.?principalType |
| 191 | + condition: roleAssignment.?condition |
| 192 | + conditionVersion: !empty(roleAssignment.?condition) ? (roleAssignment.?conditionVersion ?? '2.0') : null // Must only be set if condtion is set |
| 193 | + delegatedManagedIdentityResourceId: roleAssignment.?delegatedManagedIdentityResourceId |
| 194 | + } |
| 195 | + scope: cognitiveService |
| 196 | + } |
| 197 | +] |
0 commit comments