Skip to content

Commit

Permalink
[Modules] Added CosmosDB Gremlin API & updated mongodb to current ver…
Browse files Browse the repository at this point in the history
…sion (#1638)

* [Modules] Added CosmosDB Gremlin API and updated mongodb to… (#1566)

* feat(document-db):  Added CosmosDB Gremlin API and updated mongodb to current version

* docs(graphs):  Updated readme.md

* feat(document-db):  Added backupPolicy, updated docs

* Update arm/Microsoft.DocumentDB/databaseAccounts/deploy.bicep

Co-authored-by: Alexander Sehr <[email protected]>

* feat(gremlin-databases):  Added tests and small bugfixes

* feat(gremlin):  Updated tests, pipeline, parameters

* refactor(test):  Changed .parameters to .test

Co-authored-by: Alexander Sehr <[email protected]>

* Minor updates

* Adjusted telemetry

* Additional small updates

* Updated docs

* Applied several fixes

* Updated throughput logic

Co-authored-by: Jan-Henrik Damaschke <[email protected]>
  • Loading branch information
AlexanderSehr and itpropro authored Jul 7, 2022
1 parent b0505a6 commit 86678e9
Show file tree
Hide file tree
Showing 12 changed files with 938 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ stages:
removeDeployment: '${{ parameters.removeDeployment }}'
deploymentBlocks:
- path: $(modulePath)/.test/mongodb.parameters.json
- path: $(modulePath)/.test/gremlindb.parameters.json
- path: $(modulePath)/.test/plain.parameters.json
- path: $(modulePath)/.test/sqldb.parameters.json

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"name": {
"value": "<<namePrefix>>-az-cdb-gremlindb-001"
},
"location": {
"value": "West Europe"
},
"locations": {
"value": [
{
"locationName": "West Europe",
"failoverPriority": 0,
"isZoneRedundant": false
},
{
"locationName": "North Europe",
"failoverPriority": 1,
"isZoneRedundant": false
}
]
},
"capabilitiesToAdd": {
"value": [
"EnableGremlin"
]
},
"roleAssignments": {
"value": [
{
"roleDefinitionIdOrName": "Reader",
"principalIds": [
"<<deploymentSpId>>"
]
}
]
},
"gremlinDatabases": {
"value": [
{
"name": "<<namePrefix>>-az-gdb-x-001",
"graphs": [
{
"name": "car_collection",
"automaticIndexing": true,
"partitionKeyPaths": [
"/car_id"
]
},
{
"name": "truck_collection",
"automaticIndexing": true,
"partitionKeyPaths": [
"/truck_id"
]
}
]
},
{
"name": "<<namePrefix>>-az-gdb-x-002",
"collections": [
{
"name": "bike_collection",
"automaticIndexing": true,
"partitionKeyPaths": [
"/bike_id"
]
},
{
"name": "bicycle_collection",
"automaticIndexing": true,
"partitionKeyPaths": [
"/bicycle_id"
]
}
]
}
]
},
"diagnosticLogsRetentionInDays": {
"value": 7
},
"diagnosticStorageAccountId": {
"value": "/subscriptions/<<subscriptionId>>/resourceGroups/validation-rg/providers/Microsoft.Storage/storageAccounts/adp<<namePrefix>>azsax001"
},
"diagnosticWorkspaceId": {
"value": "/subscriptions/<<subscriptionId>>/resourcegroups/validation-rg/providers/microsoft.operationalinsights/workspaces/adp-<<namePrefix>>-az-law-x-001"
},
"diagnosticEventHubAuthorizationRuleId": {
"value": "/subscriptions/<<subscriptionId>>/resourceGroups/validation-rg/providers/Microsoft.EventHub/namespaces/adp-<<namePrefix>>-az-evhns-x-001/AuthorizationRules/RootManageSharedAccessKey"
},
"diagnosticEventHubName": {
"value": "adp-<<namePrefix>>-az-evh-x-001"
},
"systemAssignedIdentity": {
"value": true
}
}
}
113 changes: 95 additions & 18 deletions modules/Microsoft.DocumentDB/databaseAccounts/deploy.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,19 @@ param maxIntervalInSeconds int = 300
'3.2'
'3.6'
'4.0'
'4.2'
])
param serverVersion string = '4.0'
param serverVersion string = '4.2'

@description('Optional. SQL Databases configurations.')
param sqlDatabases array = []

@description('Optional. MongoDB Databases configurations.')
param mongodbDatabases array = []

@description('Optional. Gremlin Databases configurations.')
param gremlinDatabases array = []

@description('Optional. Enable telemetry via the Customer Usage Attribution ID (GUID).')
param enableDefaultTelemetry bool = true

Expand Down Expand Up @@ -125,6 +129,49 @@ param diagnosticMetricsToEnable array = [
@description('Optional. The name of the diagnostic setting, if deployed.')
param diagnosticSettingsName string = '${name}-diagnosticSettings'

@allowed([
'EnableCassandra'
'EnableTable'
'EnableGremlin'
'EnableMongo'
'DisableRateLimitingResponses'
'EnableServerless'
])
@description('Optional. List of Cosmos DB capabilities for the account.')
param capabilitiesToAdd array = []

@allowed([
'Periodic'
'Continuous'
])
@description('Optional. Describes the mode of backups.')
param backupPolicyType string = 'Continuous'

@allowed([
'Continuous30Days'
'Continuous7Days'
])
@description('Optional. Configuration values for continuous mode backup.')
param backupPolicyContinuousTier string = 'Continuous30Days'

@minValue(60)
@maxValue(1440)
@description('Optional. An integer representing the interval in minutes between two backups. Only applies to periodic backup type.')
param backupIntervalInMinutes int = 240

@minValue(2)
@maxValue(720)
@description('Optional. An integer representing the time (in hours) that each backup is retained. Only applies to periodic backup type.')
param backupRetentionIntervalInHours int = 8

@allowed([
'Geo'
'Local'
'Zone'
])
@description('Optional. Enum to indicate type of backup residency. Only applies to periodic backup type.')
param backupStorageRedundancy string = 'Local'

var diagnosticsLogs = [for category in diagnosticLogCategoriesToEnable: {
category: category
enabled: true
Expand Down Expand Up @@ -177,25 +224,45 @@ var databaseAccount_locations = [for location in locations: {
locationName: location.locationName
}]

var kind = !empty(sqlDatabases) ? 'GlobalDocumentDB' : (!empty(mongodbDatabases) ? 'MongoDB' : 'Parse')
var kind = !empty(sqlDatabases) || !empty(gremlinDatabases) ? 'GlobalDocumentDB' : (!empty(mongodbDatabases) ? 'MongoDB' : 'Parse')

var enableReferencedModulesTelemetry = false

var databaseAccount_properties = !empty(sqlDatabases) ? {
consistencyPolicy: consistencyPolicy[defaultConsistencyLevel]
locations: databaseAccount_locations
databaseAccountOfferType: databaseAccountOfferType
enableAutomaticFailover: automaticFailover
} : (!empty(mongodbDatabases) ? {
consistencyPolicy: consistencyPolicy[defaultConsistencyLevel]
locations: databaseAccount_locations
databaseAccountOfferType: databaseAccountOfferType
apiProperties: {
serverVersion: serverVersion
var capabilities = [for capability in capabilitiesToAdd: {
name: capability
}]

var backupPolicy = backupPolicyType == 'Continuous' ? {
type: backupPolicyType
continuousModeProperties: {
tier: backupPolicyContinuousTier
}
} : {
databaseAccountOfferType: databaseAccountOfferType
})
type: backupPolicyType
periodicModeProperties: {
backupIntervalInMinutes: backupIntervalInMinutes
backupRetentionIntervalInHours: backupRetentionIntervalInHours
backupStorageRedundancy: backupStorageRedundancy
}
}

var databaseAccount_properties = union({
databaseAccountOfferType: databaseAccountOfferType
}, ((!empty(sqlDatabases) || !empty(mongodbDatabases) || !empty(gremlinDatabases)) ? {
// Common properties
consistencyPolicy: consistencyPolicy[defaultConsistencyLevel]
locations: databaseAccount_locations
capabilities: capabilities
backupPolicy: backupPolicy
} : {}), (!empty(sqlDatabases) ? {
// SQLDB properties
enableAutomaticFailover: automaticFailover
} : {}), (!empty(mongodbDatabases) ? {
// MongoDb properties
apiProperties: {
serverVersion: serverVersion
}
} : {}))

resource defaultTelemetry 'Microsoft.Resources/deployments@2021-04-01' = if (enableDefaultTelemetry) {
name: 'pid-47ed15a6-730a-4827-bcb4-0fd963ffbd82-${uniqueString(deployment().name, location)}'
Expand All @@ -209,7 +276,7 @@ resource defaultTelemetry 'Microsoft.Resources/deployments@2021-04-01' = if (ena
}
}

resource databaseAccount 'Microsoft.DocumentDB/databaseAccounts@2021-06-15' = {
resource databaseAccount 'Microsoft.DocumentDB/databaseAccounts@2022-02-15-preview' = {
name: name
location: location
tags: tags
Expand Down Expand Up @@ -251,7 +318,7 @@ module databaseAccount_roleAssignments '.bicep/nested_roleAssignments.bicep' = [
}
}]

module sqlDatabases_resource 'sqlDatabases/deploy.bicep' = [for sqlDatabase in sqlDatabases: {
module databaseAccount_sqlDatabases 'sqlDatabases/deploy.bicep' = [for sqlDatabase in sqlDatabases: {
name: '${uniqueString(deployment().name, location)}-sqldb-${sqlDatabase.name}'
params: {
databaseAccountName: databaseAccount.name
Expand All @@ -261,7 +328,7 @@ module sqlDatabases_resource 'sqlDatabases/deploy.bicep' = [for sqlDatabase in s
}
}]

module mongodbDatabases_resource 'mongodbDatabases/deploy.bicep' = [for mongodbDatabase in mongodbDatabases: {
module databaseAccount_mongodbDatabases 'mongodbDatabases/deploy.bicep' = [for mongodbDatabase in mongodbDatabases: {
name: '${uniqueString(deployment().name, location)}-mongodb-${mongodbDatabase.name}'
params: {
databaseAccountName: databaseAccount.name
Expand All @@ -271,6 +338,16 @@ module mongodbDatabases_resource 'mongodbDatabases/deploy.bicep' = [for mongodbD
}
}]

module databaseAccount_gremlinDatabases 'gremlinDatabases/deploy.bicep' = [for gremlinDatabase in gremlinDatabases: {
name: '${uniqueString(deployment().name, location)}-gremlin-${gremlinDatabase.name}'
params: {
databaseAccountName: databaseAccount.name
name: gremlinDatabase.name
graphs: contains(gremlinDatabase, 'graphs') ? gremlinDatabase.graphs : []
enableDefaultTelemetry: enableReferencedModulesTelemetry
}
}]

@description('The name of the database account.')
output name string = databaseAccount.name

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
@description('Required. Name of the Gremlin database.')
param name string

@description('Optional. Tags of the Gremlin database resource.')
param tags object = {}

@description('Optional. Enables system assigned managed identity on the resource.')
param systemAssignedIdentity bool = false

@description('Optional. The ID(s) to assign to the resource.')
param userAssignedIdentities object = {}

@description('Conditional. The name of the parent Gremlin database. Required if the template is used in a standalone deployment.')
param databaseAccountName string

@description('Optional. Array of graphs to deploy in the Gremlin database.')
param graphs array = []

@description('Optional. Represents maximum throughput, the resource can scale up to. Cannot be set together with `throughput`. If `throughput` is set to something else than -1, this autoscale setting is ignored.')
param maxThroughput int = 4000

@description('Optional. Request Units per second (for example 10000). Cannot be set together with `maxThroughput`.')
param throughput int = -1

@description('Optional. Enable telemetry via the Customer Usage Attribution ID (GUID).')
param enableDefaultTelemetry bool = true

var enableReferencedModulesTelemetry = false

var identityType = systemAssignedIdentity ? (!empty(userAssignedIdentities) ? 'SystemAssigned, UserAssigned' : 'SystemAssigned') : (!empty(userAssignedIdentities) ? 'UserAssigned' : 'None')

var identity = identityType != 'None' ? {
type: identityType
userAssignedIdentities: !empty(userAssignedIdentities) ? userAssignedIdentities : null
} : null

resource defaultTelemetry 'Microsoft.Resources/deployments@2021-04-01' = if (enableDefaultTelemetry) {
name: 'pid-47ed15a6-730a-4827-bcb4-0fd963ffbd82-${uniqueString(deployment().name)}'
properties: {
mode: 'Incremental'
template: {
'$schema': 'https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#'
contentVersion: '1.0.0.0'
resources: []
}
}
}

resource databaseAccount 'Microsoft.DocumentDB/databaseAccounts@2022-02-15-preview' existing = {
name: databaseAccountName
}

var databaseOptions = contains(databaseAccount.properties.capabilities, 'EnableServerless') ? {} : {
autoscaleSettings: throughput == -1 ? {
maxThroughput: maxThroughput
} : null
throughput: throughput != -1 ? throughput : null
}

resource gremlinDatabase 'Microsoft.DocumentDB/databaseAccounts/gremlinDatabases@2022-02-15-preview' = {
name: name
tags: tags
parent: databaseAccount
identity: identity
properties: {
options: databaseOptions
resource: {
id: name
}
}
}

module gremlinDatabase_gremlinGraphs 'graphs/deploy.bicep' = [for graph in graphs: {
name: '${uniqueString(deployment().name, gremlinDatabase.name)}-gremlindb-${graph.name}'
params: {
name: graph.name
gremlinDatabaseName: name
databaseAccountName: databaseAccountName
enableDefaultTelemetry: enableReferencedModulesTelemetry
automaticIndexing: contains(graph, 'automaticIndexing') ? graph.automaticIndexing : true
partitionKeyPaths: !empty(graph.partitionKeyPaths) ? graph.partitionKeyPaths : []
}
}]

@description('The name of the Gremlin database.')
output name string = gremlinDatabase.name

@description('The resource ID of the Gremlin database.')
output resourceId string = gremlinDatabase.id

@description('The name of the resource group the Gremlin database was created in.')
output resourceGroupName string = resourceGroup().name
Loading

0 comments on commit 86678e9

Please sign in to comment.