|
1 |
| -@description('The name of the key vault') |
2 |
| -param name string |
| 1 | +param location string = resourceGroup().location |
| 2 | +param keyVaultName string = 'kv${uniqueString(resourceGroup().id)}' |
| 3 | +param enableVaultForDeployment bool = true |
| 4 | +param roleAssignments array = [] |
3 | 5 |
|
4 |
| -@description('The location of the key vault') |
5 |
| -param location string |
| 6 | +var builtInRoleNames = { |
| 7 | + Contributor: subscriptionResourceId('Microsoft.Authorization/roleDefinitions', 'b24988ac-6180-42a0-ab88-20f7382dd24c') |
| 8 | + 'Key Vault Administrator': subscriptionResourceId( |
| 9 | + 'Microsoft.Authorization/roleDefinitions', |
| 10 | + '00482a5a-887f-4fb3-b363-3b7fe8e74483' |
| 11 | + ) |
| 12 | + 'Key Vault Certificates Officer': subscriptionResourceId( |
| 13 | + 'Microsoft.Authorization/roleDefinitions', |
| 14 | + 'a4417e6f-fecd-4de8-b567-7b0420556985' |
| 15 | + ) |
| 16 | + 'Key Vault Contributor': subscriptionResourceId( |
| 17 | + 'Microsoft.Authorization/roleDefinitions', |
| 18 | + 'f25e0fa2-a7c8-4377-a976-54943a77a395' |
| 19 | + ) |
| 20 | + 'Key Vault Crypto Officer': subscriptionResourceId( |
| 21 | + 'Microsoft.Authorization/roleDefinitions', |
| 22 | + '14b46e9e-c2b7-41b4-b07b-48a6ebf60603' |
| 23 | + ) |
| 24 | + 'Key Vault Crypto Service Encryption User': subscriptionResourceId( |
| 25 | + 'Microsoft.Authorization/roleDefinitions', |
| 26 | + 'e147488a-f6f5-4113-8e2d-b22465e65bf6' |
| 27 | + ) |
| 28 | + 'Key Vault Crypto User': subscriptionResourceId( |
| 29 | + 'Microsoft.Authorization/roleDefinitions', |
| 30 | + '12338af0-0e69-4776-bea7-57ae8d297424' |
| 31 | + ) |
| 32 | + 'Key Vault Reader': subscriptionResourceId( |
| 33 | + 'Microsoft.Authorization/roleDefinitions', |
| 34 | + '21090545-7ca7-4776-b22c-e363652d74d2' |
| 35 | + ) |
| 36 | + 'Key Vault Secrets Officer': subscriptionResourceId( |
| 37 | + 'Microsoft.Authorization/roleDefinitions', |
| 38 | + 'b86a8fe4-44ce-4948-aee5-eccb2c155cd7' |
| 39 | + ) |
| 40 | + 'Key Vault Secrets User': subscriptionResourceId( |
| 41 | + 'Microsoft.Authorization/roleDefinitions', |
| 42 | + '4633458b-17de-408a-b874-0445c86b69e6' |
| 43 | + ) |
| 44 | + Owner: subscriptionResourceId('Microsoft.Authorization/roleDefinitions', '8e3af657-a8ff-443c-a75c-2fe8c4bcb635') |
| 45 | + Reader: subscriptionResourceId('Microsoft.Authorization/roleDefinitions', 'acdd72a7-3385-48ef-bd42-f606fba81ae7') |
| 46 | + 'Role Based Access Control Administrator (Preview)': subscriptionResourceId( |
| 47 | + 'Microsoft.Authorization/roleDefinitions', |
| 48 | + 'f58310d9-a9f6-439a-9e8d-f62e7b41a168' |
| 49 | + ) |
| 50 | + 'User Access Administrator': subscriptionResourceId( |
| 51 | + 'Microsoft.Authorization/roleDefinitions', |
| 52 | + '18d7d88d-d35e-4fb5-a5c3-7773c20a72d9' |
| 53 | + ) |
| 54 | +} |
6 | 55 |
|
7 |
| -resource keyVault 'Microsoft.KeyVault/vaults@2023-07-01' = { |
8 |
| - name: name |
| 56 | +resource keyVault 'Microsoft.KeyVault/vaults@2022-07-01' = { |
| 57 | + name: keyVaultName |
9 | 58 | location: location
|
10 | 59 | properties: {
|
| 60 | + enabledForDeployment: enableVaultForDeployment |
| 61 | + enableRbacAuthorization: true |
| 62 | + enableSoftDelete: true |
| 63 | + enabledForTemplateDeployment: true |
11 | 64 | sku: {
|
12 | 65 | family: 'A'
|
13 | 66 | name: 'standard'
|
14 | 67 | }
|
15 | 68 | tenantId: subscription().tenantId
|
16 |
| - enabledForDeployment: true |
17 |
| - enabledForTemplateDeployment: true |
18 |
| - enableRbacAuthorization: true |
| 69 | + accessPolicies: [] |
19 | 70 | }
|
20 | 71 | }
|
21 | 72 |
|
| 73 | +resource keyVault_roleAssignments 'Microsoft.Authorization/roleAssignments@2022-04-01' = [ |
| 74 | + for (roleAssignment, index) in (roleAssignments ?? []): { |
| 75 | + name: guid(keyVault.id, roleAssignment.principalId, roleAssignment.roleDefinitionIdOrName) |
| 76 | + properties: { |
| 77 | + roleDefinitionId: builtInRoleNames[?roleAssignment.roleDefinitionIdOrName] ?? roleAssignment.roleDefinitionIdOrName |
| 78 | + principalId: roleAssignment.principalId |
| 79 | + description: roleAssignment.?description |
| 80 | + principalType: roleAssignment.?principalType |
| 81 | + condition: roleAssignment.?condition |
| 82 | + conditionVersion: !empty(roleAssignment.?condition) ? (roleAssignment.?conditionVersion ?? '2.0') : null |
| 83 | + delegatedManagedIdentityResourceId: roleAssignment.?delegatedManagedIdentityResourceId |
| 84 | + } |
| 85 | + scope: keyVault |
| 86 | + } |
| 87 | +] |
| 88 | + |
22 | 89 | output keyVaultName string = keyVault.name
|
23 |
| -output keyVaultUri string = keyVault.properties.vaultUri |
| 90 | +output keyVaultResourceId string = keyVault.id |
0 commit comments