|
| 1 | +@description('The base resource name.') |
| 2 | +param baseName string |
| 3 | + |
| 4 | +@description('The principal to assign the role to. This is application object id.') |
| 5 | +param testApplicationOid string |
| 6 | + |
| 7 | +@description('The url suffix to use when accessing the storage data plane.') |
| 8 | +param storageEndpointSuffix string = 'core.windows.net' |
| 9 | + |
| 10 | +@description('The url suffix to use when accessing the cosmos data plane.') |
| 11 | +param cosmosEndpointSuffix string = 'cosmos.azure.com' |
| 12 | + |
| 13 | +var location = resourceGroup().location |
| 14 | +var primaryAccountName = '${replace(replace(baseName, '-', ''), '_', '')}prim' |
| 15 | + |
| 16 | +var customCosmosRoleName = 'Azure Cosmos DB SDK role for Table Data Plane' |
| 17 | + |
| 18 | +resource roleAssignment 'Microsoft.Authorization/roleAssignments@2018-09-01-preview' = { |
| 19 | + name: guid('tableDataContributorRoleId', resourceGroup().id) |
| 20 | + properties: { |
| 21 | + roleDefinitionId: subscriptionResourceId('Microsoft.Authorization/roleDefinitions', '0a9a7e1f-b9d0-4cc4-a60d-0319b160aaa3') |
| 22 | + principalId: testApplicationOid |
| 23 | + } |
| 24 | +} |
| 25 | + |
| 26 | +resource storageAccount 'Microsoft.Storage/storageAccounts@2023-05-01' = { |
| 27 | + name: primaryAccountName |
| 28 | + location: location |
| 29 | + sku: { |
| 30 | + name: 'Standard_RAGRS' |
| 31 | + } |
| 32 | + kind: 'StorageV2' |
| 33 | + properties: { |
| 34 | + networkAcls: { |
| 35 | + bypass: 'AzureServices' |
| 36 | + virtualNetworkRules: [] |
| 37 | + ipRules: [] |
| 38 | + defaultAction: 'Allow' |
| 39 | + } |
| 40 | + supportsHttpsTrafficOnly: true |
| 41 | + encryption: { |
| 42 | + services: { |
| 43 | + file: { |
| 44 | + enabled: true |
| 45 | + } |
| 46 | + blob: { |
| 47 | + enabled: true |
| 48 | + } |
| 49 | + } |
| 50 | + keySource: 'Microsoft.Storage' |
| 51 | + } |
| 52 | + accessTier: 'Cool' |
| 53 | + minimumTlsVersion: 'TLS1_2' |
| 54 | + } |
| 55 | +} |
| 56 | + |
| 57 | +resource cosmosAccount 'Microsoft.DocumentDB/databaseAccounts@2020-04-01' = { |
| 58 | + name: primaryAccountName |
| 59 | + location: location |
| 60 | + tags: { |
| 61 | + defaultExperience: 'Azure Table' |
| 62 | + CosmosAccountType: 'Non-Production' |
| 63 | + } |
| 64 | + kind: 'GlobalDocumentDB' |
| 65 | + properties: { |
| 66 | + enableAutomaticFailover: false |
| 67 | + enableMultipleWriteLocations: false |
| 68 | + isVirtualNetworkFilterEnabled: false |
| 69 | + virtualNetworkRules: [] |
| 70 | + disableKeyBasedMetadataWriteAccess: false |
| 71 | + enableFreeTier: false |
| 72 | + enableAnalyticalStorage: false |
| 73 | + databaseAccountOfferType: 'Standard' |
| 74 | + consistencyPolicy: { |
| 75 | + defaultConsistencyLevel: 'BoundedStaleness' |
| 76 | + maxIntervalInSeconds: 86400 |
| 77 | + maxStalenessPrefix: 1000000 |
| 78 | + } |
| 79 | + locations: [ |
| 80 | + { |
| 81 | + locationName: location |
| 82 | + failoverPriority: 0 |
| 83 | + isZoneRedundant: false |
| 84 | + } |
| 85 | + ] |
| 86 | + capabilities: [ |
| 87 | + { |
| 88 | + name: 'EnableTable' |
| 89 | + } |
| 90 | + ] |
| 91 | + ipRules: [] |
| 92 | + } |
| 93 | +} |
| 94 | + |
| 95 | +resource cosmosRoleDef 'Microsoft.DocumentDB/databaseAccounts/tableRoleDefinitions@2024-12-01-preview' = { |
| 96 | + name: guid(customCosmosRoleName, 'roleDefinitionId') |
| 97 | + parent: cosmosAccount |
| 98 | + properties: { |
| 99 | + roleName: customCosmosRoleName |
| 100 | + permissions: [ |
| 101 | + { |
| 102 | + dataActions: [ |
| 103 | + 'Microsoft.DocumentDB/databaseAccounts/readMetadata' |
| 104 | + 'Microsoft.DocumentDB/databaseAccounts/tables/*' |
| 105 | + 'Microsoft.DocumentDB/databaseAccounts/tables/containers/*' |
| 106 | + 'Microsoft.DocumentDB/databaseAccounts/tables/containers/entities/*' |
| 107 | + 'Microsoft.DocumentDB/databaseAccounts/throughputSettings/read' |
| 108 | + ] |
| 109 | + } |
| 110 | + ] |
| 111 | + assignableScopes: [ |
| 112 | + cosmosAccount.id |
| 113 | + ] |
| 114 | + } |
| 115 | +} |
| 116 | + |
| 117 | +resource cosmosRoleAssignment 'Microsoft.DocumentDB/databaseAccounts/tableRoleAssignments@2024-12-01-preview' = { |
| 118 | + name: guid(customCosmosRoleName, 'roleAssignmentId') |
| 119 | + parent: cosmosAccount |
| 120 | + properties: { |
| 121 | + scope: cosmosAccount.id |
| 122 | + roleDefinitionId: cosmosRoleDef.id |
| 123 | + principalId: testApplicationOid |
| 124 | + } |
| 125 | +} |
| 126 | + |
| 127 | +output TABLES_STORAGE_ENDPOINT_SUFFIX string = storageEndpointSuffix |
| 128 | +output TABLES_STORAGE_ACCOUNT_NAME string = primaryAccountName |
| 129 | +output TABLES_PRIMARY_STORAGE_ACCOUNT_KEY string = storageAccount.listKeys().keys[0].value |
| 130 | +output TABLES_COSMOS_ENDPOINT_SUFFIX string = cosmosEndpointSuffix |
| 131 | +output TABLES_COSMOS_ACCOUNT_NAME string = primaryAccountName |
| 132 | +output TABLES_PRIMARY_COSMOS_ACCOUNT_KEY string = cosmosAccount.listKeys().primaryMasterKey |
0 commit comments