test-resources.bicep•3.58 kB
targetScope = 'resourceGroup'
@minLength(3)
@maxLength(50)
@description('The base resource name.')
param baseName string = resourceGroup().name
@description('The location of the resource. By default, this is the same as the resource group.')
param location string = resourceGroup().location
@description('The tenant ID to which the application and resources belong.')
param tenantId string = '72f988bf-86f1-41af-91ab-2d7cd011db47'
@description('The client OID to grant access to test resources.')
param testApplicationOid string
var cosmosContributorRoleId = '00000000-0000-0000-0000-000000000002' // Built-in Contributor role
resource cosmosAccount 'Microsoft.DocumentDB/databaseAccounts@2024-11-15' = {
name: baseName
location: location
tags: {
defaultExperience: 'Core (SQL)'
CosmosAccountType: 'Non-Production'
}
kind: 'GlobalDocumentDB'
identity: {
type: 'None'
}
properties: {
publicNetworkAccess: 'Enabled'
enableAutomaticFailover: false
enableMultipleWriteLocations: false
isVirtualNetworkFilterEnabled: false
virtualNetworkRules: []
disableKeyBasedMetadataWriteAccess: false
enableFreeTier: false
enableAnalyticalStorage: false
analyticalStorageConfiguration: {
schemaType: 'WellDefined'
}
databaseAccountOfferType: 'Standard'
defaultIdentity: 'FirstPartyIdentity'
networkAclBypass: 'None'
disableLocalAuth: true
enablePartitionMerge: false
enablePerRegionPerPartitionAutoscale: false
enableBurstCapacity: false
minimalTlsVersion: 'Tls12'
consistencyPolicy: {
defaultConsistencyLevel: 'Session'
maxIntervalInSeconds: 5
maxStalenessPrefix: 100
}
locations: [
{
locationName: location
failoverPriority: 0
isZoneRedundant: false
}
]
cors: []
capabilities: []
ipRules: []
backupPolicy: {
type: 'Periodic'
periodicModeProperties: {
backupIntervalInMinutes: 240
backupRetentionIntervalInHours: 8
backupStorageRedundancy: 'Geo'
}
}
networkAclBypassResourceIds: []
}
}
resource cosmosDatabase 'Microsoft.DocumentDB/databaseAccounts/sqlDatabases@2024-11-15' = {
parent: cosmosAccount
name: 'ToDoList'
properties: {
resource: {
id: 'ToDoList'
}
}
}
resource cosmosContainer 'Microsoft.DocumentDB/databaseAccounts/sqlDatabases/containers@2024-11-15' = {
parent: cosmosDatabase
name: 'Items'
properties: {
resource: {
id: 'Items'
indexingPolicy: {
indexingMode: 'consistent'
automatic: true
includedPaths: [
{
path: '/*'
}
]
excludedPaths: [
{
path: '/"_etag"/?'
}
]
}
partitionKey: {
paths: [
'/id'
]
kind: 'Hash'
}
uniqueKeyPolicy: {
uniqueKeys: []
}
conflictResolutionPolicy: {
mode: 'LastWriterWins'
conflictResolutionPath: '/_ts'
}
}
}
}
// Assign CosmosDB Contributor role for the Web App on the Cosmos Account
resource sqlRoleAssignment 'Microsoft.DocumentDB/databaseAccounts/sqlRoleAssignments@2024-11-15' = {
name: guid(cosmosContributorRoleId, testApplicationOid, cosmosAccount.id)
parent: cosmosAccount
properties:{
principalId: testApplicationOid
roleDefinitionId: '${resourceGroup().id}/providers/Microsoft.DocumentDB/databaseAccounts/${cosmosAccount.name}/sqlRoleDefinitions/${cosmosContributorRoleId}'
scope: cosmosAccount.id
}
}