Skip to content

Commit 23af4f3

Browse files
author
Adrian Hall
committed
(#244) Added Cosmos MongoDB infrastructure files
1 parent 128aef0 commit 23af4f3

File tree

4 files changed

+197
-0
lines changed

4 files changed

+197
-0
lines changed

infra/main.bicep

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ module resources './resources.bicep' = {
5050

5151
output AZSQL_CONNECTION_STRING string = resources.outputs.AZSQL_CONNECTIONSTRING
5252
output COSMOS_CONNECTION_STRING string = resources.outputs.COSMOS_CONNECTIONSTRING
53+
output MONGO_CONNECTION_STRING string = resources.outputs.MONGO_CONNECTIONSTRING
5354
output MYSQL_CONNECTION_STRING string = resources.outputs.MYSQL_CONNECTIONSTRING
5455
output PGSQL_CONNECTION_STRING string = resources.outputs.PGSQL_CONNECTIONSTRING
5556
output SERVICE_ENDPOINT string = resources.outputs.SERVICE_ENDPOINT

infra/modules/cosmos-mongodb.bicep

Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
targetScope = 'resourceGroup'
2+
3+
@minLength(1)
4+
@description('The name of the test container to create')
5+
param containerName string = 'Movies'
6+
7+
@minLength(1)
8+
@description('The name of the test database to create')
9+
param databaseName string = 'unittests'
10+
11+
@minLength(1)
12+
@description('Primary location for all resources')
13+
param location string = resourceGroup().location
14+
15+
@allowed(['3.2', '3.6', '4.0', '4.2'])
16+
@description('Specifies the MongoDB server version to use.')
17+
param mongoVersion string = '4.2'
18+
19+
@description('The name of the Mongo Server to create.')
20+
param serverName string
21+
22+
@description('The list of tags to apply to all resources.')
23+
param tags object = {}
24+
25+
/*********************************************************************************/
26+
27+
var compositeIndices = [
28+
[
29+
{ path: '/BestPictureWinner', order: 'ascending' }
30+
{ path: '/id', order: 'ascending' }
31+
]
32+
[
33+
{ path: '/BestPictureWinner', order: 'descending' }
34+
{ path: '/id', order: 'ascending' }
35+
]
36+
[
37+
{ path: '/Duration', order: 'ascending' }
38+
{ path: '/id', order: 'ascending' }
39+
]
40+
[
41+
{ path: '/Duration', order: 'descending' }
42+
{ path: '/id', order: 'ascending' }
43+
]
44+
[
45+
{ path: '/Rating', order: 'ascending' }
46+
{ path: '/id', order: 'ascending' }
47+
]
48+
[
49+
{ path: '/Rating', order: 'descending' }
50+
{ path: '/id', order: 'ascending' }
51+
]
52+
[
53+
{ path: '/ReleaseDate', order: 'ascending' }
54+
{ path: '/id', order: 'ascending' }
55+
]
56+
[
57+
{ path: '/ReleaseDate', order: 'descending' }
58+
{ path: '/id', order: 'ascending' }
59+
]
60+
[
61+
{ path: '/Title', order: 'ascending' }
62+
{ path: '/id', order: 'ascending' }
63+
]
64+
[
65+
{ path: '/Title', order: 'descending' }
66+
{ path: '/id', order: 'ascending' }
67+
]
68+
[
69+
{ path: '/UpdatedAt', order: 'ascending' }
70+
{ path: '/id', order: 'ascending' }
71+
]
72+
[
73+
{ path: '/UpdatedAt', order: 'descending' }
74+
{ path: '/id', order: 'ascending' }
75+
]
76+
[
77+
{ path: '/Year', order: 'ascending' }
78+
{ path: '/id', order: 'ascending' }
79+
]
80+
[
81+
{ path: '/Year', order: 'descending' }
82+
{ path: '/id', order: 'ascending' }
83+
]
84+
[
85+
{ path: '/Year', order: 'ascending' }
86+
{ path: '/Title', order: 'ascending' }
87+
{ path: '/id', order: 'ascending' }
88+
]
89+
[
90+
{ path: '/Year', order: 'descending' }
91+
{ path: '/Title', order: 'ascending' }
92+
{ path: '/id', order: 'ascending' }
93+
]
94+
[
95+
{ path: '/Year', order: 'ascending' }
96+
{ path: '/Title', order: 'descending' }
97+
{ path: '/id', order: 'ascending' }
98+
]
99+
[
100+
{ path: '/Year', order: 'descending' }
101+
{ path: '/Title', order: 'descending' }
102+
{ path: '/id', order: 'ascending' }
103+
]
104+
]
105+
106+
/*********************************************************************************/
107+
108+
resource account 'Microsoft.DocumentDB/databaseAccounts@2022-05-15' = {
109+
name: toLower(serverName)
110+
location: location
111+
kind: 'MongoDB'
112+
tags: tags
113+
properties: {
114+
apiProperties: {
115+
serverVersion: mongoVersion
116+
}
117+
capabilities: [
118+
{
119+
name: 'DisableRateLimitingResponses'
120+
}
121+
]
122+
consistencyPolicy: {
123+
defaultConsistencyLevel: 'Session'
124+
}
125+
databaseAccountOfferType: 'Standard'
126+
disableLocalAuth: false
127+
locations: [
128+
{
129+
locationName: location
130+
isZoneRedundant: false
131+
}
132+
]
133+
}
134+
}
135+
136+
resource database 'Microsoft.DocumentDB/databaseAccounts/mongodbDatabases@2022-05-15' = {
137+
parent: account
138+
name: databaseName
139+
tags: tags
140+
properties: {
141+
resource: {
142+
id: databaseName
143+
}
144+
options: {
145+
throughput: 400
146+
}
147+
}
148+
}
149+
150+
resource collection 'Microsoft.DocumentDb/databaseAccounts/mongodbDatabases/collections@2022-05-15' = {
151+
parent: database
152+
name: containerName
153+
tags: tags
154+
properties: {
155+
resource: {
156+
id: containerName
157+
shardKey: {
158+
_id: 'Hash'
159+
}
160+
indexes: [
161+
{
162+
key: {
163+
keys: [
164+
'_id'
165+
]
166+
}
167+
}
168+
{
169+
key: {
170+
keys: [
171+
'$**'
172+
]
173+
}
174+
}
175+
]
176+
}
177+
}
178+
}
179+
/*********************************************************************************/
180+
181+
#disable-next-line outputs-should-not-contain-secrets
182+
output MONGODB_CONNECTIONSTRING string = 'mongodb://${account.properties.documentEndpoint}/${containerName}'

infra/resources.bicep

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ var azsqlServerName = 'sql-${resourceToken}'
3535
var cosmosServerName = 'cosmos-${resourceToken}'
3636
var pgsqlServerName = 'pgsql-${resourceToken}'
3737
var mysqlServerName = 'mysql-${resourceToken}'
38+
var mongoServerName = 'mongo-${resourceToken}'
3839

3940
var testDatabaseName = 'unittests'
4041
var cosmosContainerName = 'Movies'
@@ -103,6 +104,17 @@ module cosmos './modules/cosmos.bicep' = {
103104
}
104105
}
105106

107+
module mongodb './modules/cosmos-mongodb.bicep' = {
108+
name: 'mongo-deployment-${resourceToken}'
109+
params: {
110+
location: location
111+
tags: tags
112+
databaseName: testDatabaseName
113+
containerName: cosmosContainerName
114+
serverName: mongoServerName
115+
}
116+
}
117+
106118
module app_service './modules/appservice.bicep' = {
107119
name: 'appsvc-deployment-${resourceToken}'
108120
params: {
@@ -124,6 +136,7 @@ module app_service './modules/appservice.bicep' = {
124136

125137
output AZSQL_CONNECTIONSTRING string = azuresql.outputs.AZSQL_CONNECTIONSTRING
126138
output COSMOS_CONNECTIONSTRING string = cosmos.outputs.COSMOS_CONNECTIONSTRING
139+
output MONGO_CONNECTIONSTRING string = mongodb.outputs.MONGODB_CONNECTIONSTRING
127140
output MYSQL_CONNECTIONSTRING string = mysql.outputs.MYSQL_CONNECTIONSTRING
128141
output PGSQL_CONNECTIONSTRING string = pgsql.outputs.PGSQL_CONNECTIONSTRING
129142
output SERVICE_ENDPOINT string = app_service.outputs.SERVICE_ENDPOINT

infra/scripts/write-runsettings.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ $fileContents = @"
1313
<EnvironmentVariables>
1414
<DATASYNC_AZSQL_CONNECTIONSTRING>$($outputs.AZSQL_CONNECTION_STRING)</DATASYNC_AZSQL_CONNECTIONSTRING>
1515
<DATASYNC_COSMOS_CONNECTIONSTRING>$($outputs.COSMOS_CONNECTION_STRING)</DATASYNC_COSMOS_CONNECTIONSTRING>
16+
<DATASYNC_MONGO_CONNECTIONSTRING>$($outputs.MONGO_CONNECTION_STRING)</DATASYNC_MONGO_CONNECTIONSTRING>
1617
<DATASYNC_MYSQL_CONNECTIONSTRING>$($outputs.MYSQL_CONNECTION_STRING)</DATASYNC_MYSQL_CONNECTIONSTRING>
1718
<DATASYNC_PGSQL_CONNECTIONSTRING>$($outputs.PGSQL_CONNECTION_STRING)</DATASYNC_PGSQL_CONNECTIONSTRING>
1819
<DATASYNC_SERVICE_ENDPOINT>$($outputs.SERVICE_ENDPOINT)</DATASYNC_SERVICE_ENDPOINT>

0 commit comments

Comments
 (0)