This repository has been archived by the owner on Sep 10, 2022. It is now read-only.
forked from sam-cogan/SmartThingsCollector
-
Notifications
You must be signed in to change notification settings - Fork 0
/
azuredeploy.json
297 lines (291 loc) · 12.6 KB
/
azuredeploy.json
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"KeyVaultName": {
"type": "string",
"metadata": {
"description": "Name of Azure Keyvault to retrieve secrets from"
},
"defaultValue": "STCaptureKV"
},
"StorageAccountName": {
"type": "string",
"metadata": {
"description": "Name of the storage account to store and retrieve event data from"
},
"defaultValue": "stcapturestg"
},
"CaptureContainerName": {
"type": "string",
"metadata": {
"description": "Name of the container in the storage account to store and retrieve event data from"
},
"defaultValue": "eventcapture"
},
"FunctionContainerName": {
"type": "string",
"metadata": {
"description": "Name of the container in the storage account to store and retrieve event data from"
},
"defaultValue": "functionfiles"
},
"FunctionName": {
"type": "string",
"metadata": {
"description": "Name for the Azure Function to Create"
},
"defaultValue": "STCaptureFunc"
},
"FunctionIntervalInMinutes": {
"type": "string",
"metadata": {
"description": "How often to execute the function"
},
"defaultValue": "15"
},
"CosmosDBAccount": {
"type": "string",
"metadata": {
"description": "Name of Cosmos DB Account to store data in"
}
},
"CosmosDBDatabase": {
"type": "string",
"metadata": {
"description": "Name of Cosmos DB Database to store data in"
}
},
"CosmosDBCollection": {
"type": "string",
"metadata": {
"description": "Name of Cosmos DB Collection to store data in"
}
},
"CosmosDBResourceGroup": {
"type": "string",
"metadata": {
"description": "Resource Group that contains your Cosmos DB instance"
}
},
"UploadFunctionFiles":{
"type":"bool",
"metadata": {
"description":"Whether to run the ACI instance to upload the Function data to storage"
},
"defaultValue": true
}
},
"variables": {
"storageAccountName": "[concat(parameters('StorageAccountName'),take(uniqueString(resourceGroup().id),5))]",
"keyvaultName": "[concat(parameters('KeyVaultName'),take(uniqueString(resourceGroup().id),5))]",
"functionName": "[concat(parameters('FunctionName'),take(uniqueString(resourceGroup().id),5))]",
"storageAccountId": "[resourceId('Microsoft.Storage/storageAccounts', variables('StorageAccountName'))]",
"CosmosResourceId": "[resourceId(parameters('CosmosDBResourceGroup'),'Microsoft.DocumentDB/databaseAccounts', parameters('CosmosDBAccount'))]",
"CosmosApiVersion": "[providers('Microsoft.DocumentDB', 'databaseAccounts').apiVersions[0]]",
"FunctionZipName": "SmartThingsCollector.zip"
},
"resources": [
{
"type": "Microsoft.Storage/storageAccounts",
"apiVersion": "2018-02-01",
"name": "[variables('StorageAccountName')]",
"location": "[resourceGroup().location]",
"tags": {
"displayName": "[variables('StorageAccountName')]"
},
"sku": {
"name": "Standard_LRS"
},
"kind": "StorageV2",
"properties": {},
"resources": [
{
"type": "blobServices/containers",
"apiVersion": "2018-03-01-preview",
"name": "[concat('default/', parameters('CaptureContainerName'))]",
"dependsOn": [
"[variables('StorageAccountName')]"
]
},
{
"type": "blobServices/containers",
"apiVersion": "2018-03-01-preview",
"name": "[concat('default/', parameters('FunctionContainerName'))]",
"properties": {
"publicAccess": "Blob"
},
"dependsOn": [
"[variables('StorageAccountName')]"
]
}
]
},
{
"type": "Microsoft.ContainerInstance/containerGroups",
"apiVersion": "2017-10-01-preview",
"name": "[concat(variables('StorageAccountName'),'-aci')]",
"location": "[resourceGroup().location]",
"dependsOn": [
"[resourceId('Microsoft.Storage/storageAccounts', variables('StorageAccountName'))]"
],
"condition":"[parameters('UploadFunctionFiles')]",
"properties": {
"containers": [
{
"name": "[concat(variables('StorageAccountName'),'-aci')]",
"properties": {
"command":["azcopy",
"--source",
"https://scartifactstorage.blob.core.windows.net/smartthingscollector",
"--destination",
"[concat('https://',variables('storageAccountName'),'.blob.core.windows.net/',parameters('FunctionContainerName'))]",
"--dest-key",
"[listKeys(variables('storageAccountid') ,'2015-05-01-preview').key1]",
"--include",
"SmartThingsCollector.zip",
"--quiet"
],
"image": "samcogan/azcopy",
"resources": {
"requests": {
"cpu": 1,
"memoryInGB": 1
}
}
}
}
],
"osType": "Linux",
"restartPolicy": "Never"
}
},
{
"type": "Microsoft.Web/serverfarms",
"apiVersion": "2015-04-01",
"name": "[concat(variables('FunctionName'),'-plan')]",
"location": "[resourceGroup().location]",
"properties": {
"name": "[concat(variables('FunctionName'),'-plan')]",
"computeMode": "Dynamic",
"sku": "Dynamic"
}
},
{
"apiVersion": "2015-08-01",
"name": "[variables('FunctionName')]",
"type": "Microsoft.Web/sites",
"location": "[resourceGroup().location]",
"kind": "functionapp",
"identity": {
"type": "SystemAssigned"
},
"dependsOn": [
"[resourceId('Microsoft.Web/serverfarms', concat(variables('FunctionName'),'-plan'))]",
"[resourceId('Microsoft.Storage/storageAccounts', variables('StorageAccountName'))]",
"[resourceId('Microsoft.ContainerInstance/containerGroups', concat(variables('StorageAccountName'),'-aci'))]"
],
"properties": {
"serverFarmId": "[resourceId('Microsoft.Web/serverfarms', concat(variables('FunctionName'),'-plan'))]",
"siteConfig": {
"connectionStrings": [
{
"name": "CosmosDBConnection",
"connectionString": "[concat('AccountEndpoint=https://', parameters('CosmosDBAccount'), '.documents.azure.com:443/;AccountKey=', listKeys(variables('CosmosResourceId'), variables('CosmosApiVersion')).primaryMasterKey, ';')]"
}
],
"appSettings": [
{
"name": "AzureWebJobsDashboard",
"value": "[concat('DefaultEndpointsProtocol=https;AccountName=', variables('storageAccountName'), ';AccountKey=', listKeys(variables('storageAccountid'),'2015-05-01-preview').key1)]"
},
{
"name": "AzureWebJobsStorage",
"value": "[concat('DefaultEndpointsProtocol=https;AccountName=', variables('storageAccountName'), ';AccountKey=', listKeys(variables('storageAccountid'),'2015-05-01-preview').key1)]"
},
{
"name": "FUNCTIONS_EXTENSION_VERSION",
"value": "~2"
},
{
"name": "KeyvaultName",
"value": "[variables('KeyVaultName')]"
},
{
"name": "StorageAccountName",
"value": "[variables('storageAccountName')]"
},
{
"name": "StorageContainerName",
"value": "[parameters('CaptureContainerName')]"
},
{
"name": "TimerInterval",
"value": "[concat('0 */',parameters('FunctionIntervalInMinutes') , ' * * * *')]"
},
{
"name": "ComsosDatabase",
"value": "[parameters('CosmosDBDatabase')]"
},
{
"name": "CosmosCollection",
"value": "[parameters('CosmosDBCollection')]"
},
{
"name": "StorageAccountKeySecretName",
"value": "StorageAccountKeySecret"
},
{
"name": "WEBSITE_RUN_FROM_PACKAGE",
"value": "[concat('https://',variables('storageAccountName'),'.blob.core.windows.net/',parameters('functionContainerName'),'/', variables('FunctionZipName'))]"
}
]
}
}
},
{
"type": "Microsoft.KeyVault/vaults",
"apiVersion": "2015-06-01",
"name": "[variables('KeyVaultName')]",
"location": "[resourceGroup().location]",
"tags": {
"displayName": "[variables('KeyVaultName')]"
},
"properties": {
"tenantId": "[reference(concat('Microsoft.Web/sites/', variables('FunctionName')), '2015-08-01', 'Full').identity.tenantId]",
"enabledForDeployment": true,
"enabledForTemplateDeployment": true,
"enabledForDiskEncryption": true,
"accessPolicies": [
{
"objectId": "[reference(concat('Microsoft.Web/sites/', variables('FunctionName')), '2015-08-01', 'Full').identity.principalId]",
"tenantId": "[reference(concat('Microsoft.Web/sites/', variables('FunctionName')), '2015-08-01', 'Full').identity.tenantId]",
"permissions": {
"secrets": [
"list",
"get"
]
}
}
],
"sku": {
"name": "standard",
"family": "A"
}
},
"resources": []
},
{
"apiVersion": "2015-06-01",
"type": "Microsoft.KeyVault/vaults/secrets",
"name": "[concat(variables('keyvaultName'), '/', 'StorageAccountKeySecret')]",
"dependsOn": [
"[resourceId('Microsoft.KeyVault/vaults', concat(variables('keyvaultName')))]"
],
"properties": {
"value": "[listKeys(variables('storageAccountid'),'2015-05-01-preview').key1]"
}
}
],
"outputs": {}
}