-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathazuredeploy.json
More file actions
385 lines (385 loc) · 21.3 KB
/
azuredeploy.json
File metadata and controls
385 lines (385 loc) · 21.3 KB
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
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"languageVersion": "2.0",
"contentVersion": "1.0.0.0",
"metadata": {
"_generator": {
"name": "bicep",
"version": "0.37.4.10188",
"templateHash": "18084735929345665494"
}
},
"parameters": {
"tenantId": {
"type": "string",
"defaultValue": "[tenant().tenantId]",
"metadata": {
"description": "Id (guid) of the tenant of the D365FO environment.\nYou can find the tenant id in the about form of the D365FO environment in the licenses section under the name \"Serial number\".\nBy default, the tenant id of the Azure Directory where this template is deployed will be used.\n"
}
},
"d365FOEnvironmentUrl": {
"type": "string",
"defaultValue": "https://d365fo-environment-url.dynamics.com",
"metadata": {
"description": "URL of the D365FO environment.\n"
}
},
"clientId": {
"type": "string",
"defaultValue": "00000000-0000-0000-0000-000000000000",
"metadata": {
"description": "Id (guid) of app registration client for OAuth2.0 authentication with D365FO environment. \nSee https://learn.microsoft.com/en-us/dynamics365/fin-ops-core/dev-itpro/data-entities/services-home-page#authentication for more details.\nWill be stored as a named value in API Management.\n"
}
},
"clientSecret": {
"type": "securestring",
"metadata": {
"description": "Client secret for OAuth2.0 authentication with D365FO environment. \nSee https://learn.microsoft.com/en-us/dynamics365/fin-ops-core/dev-itpro/data-entities/services-home-page#authentication for more details.\nWill be stored as a secret named value in API Management.\n"
}
}
},
"variables": {
"$fxv#0": "openapi: 3.0.1\ninfo:\n title: D365FO\n version: '0.1'\npaths:\n /*:\n patch:\n summary: PATCH\n operationId: PATCH\n responses:\n '200':\n description: ''\n delete:\n summary: DELETE\n operationId: DELETE\n responses:\n '200':\n description: ''\n get:\n summary: GET\n operationId: GET\n responses:\n '200':\n description: ''\n put:\n summary: PUT\n operationId: PUT\n responses:\n '200':\n description: ''\n post:\n summary: POST\n operationId: POST\n responses:\n '200':\n description: ''\ncomponents:\n securitySchemes:\n apiKeyHeader:\n type: apiKey\n name: Ocp-Apim-Subscription-Key\n in: header\n apiKeyQuery:\n type: apiKey\n name: subscription-key\n in: query\nsecurity:\n - apiKeyHeader: [ ]\n - apiKeyQuery: [ ]",
"$fxv#1": "<!--\n IMPORTANT:\n - Policy elements can appear only within the <inbound>, <outbound>, <backend> section elements.\n - To apply a policy to the incoming request (before it is forwarded to the backend service), place a corresponding policy element within the <inbound> section element.\n - To apply a policy to the outgoing response (before it is sent back to the caller), place a corresponding policy element within the <outbound> section element.\n - To add a policy, place the cursor at the desired insertion point and select a policy from the sidebar.\n - To remove a policy, delete the corresponding policy statement from the policy document.\n - Position the <base> element within a section element to inherit all policies from the corresponding section element in the enclosing scope.\n - Remove the <base> element to prevent inheriting policies from the corresponding section element in the enclosing scope.\n - Policies are applied in the order of their appearance, from the top down.\n - Comments within policy elements are not supported and may disappear. Place your comments between policy elements or at a higher level scope.\n-->\n<policies>\n\t<inbound>\n\t\t<base />\n\t\t<!-- Log all incoming request headers -->\n\t\t<include-fragment fragment-id=\"LogHeaders\" />\n\t\t<!-- Allow requester to determine backend based on Environment header -->\n\t\t<include-fragment fragment-id=\"SetEnvironmentVariable\" />\n\t\t<include-fragment fragment-id=\"SetServiceBackendBasedOnEnvironmentVariable\" />\n\t\t<!-- Get OAuth bearer token for authentication with D365FO -->\n\t\t<include-fragment fragment-id=\"SetMicrosoftOAuthorizationHeaderCached\" />\n\t\t<!-- Add cross-company=true parameter to all requests -->\n\t\t<include-fragment fragment-id=\"AddCrossCompanyParameter\" />\n\t</inbound>\n\t<backend>\n\t\t<base />\n\t</backend>\n\t<outbound>\n\t\t<base />\n\t</outbound>\n\t<on-error>\n\t\t<base />\n\t</on-error>\n</policies>",
"policyFragments": "[variables('_1.fragments')]",
"applicationInsightsName": "[format('appInsights{0}', uniqueString(resourceGroup().id))]",
"appInsightsInstrumentationKeyNamedValueName": "ApplicationInsightsInstrumentationKey",
"logSettings": {
"request": {
"body": {
"bytes": 8192
}
},
"response": {
"body": {
"bytes": 8192
}
}
},
"_1._2": "<!--\n - <inbound> fragment\n-->\n<fragment>\n\t<set-query-parameter name=\"cross-company\" exists-action=\"override\">\n\t\t<value>true</value>\n\t</set-query-parameter>\n</fragment>",
"_1._3": "<!--\n - <outbound> fragment\n-->\n<fragment>\n\t<retry condition=\"@(context.Response.StatusCode == 429)\" count=\"3\" interval=\"10\" first-fast-retry=\"false\" />\n</fragment>",
"_1._4": "<!-- \n - <inbound> fragment\n-->\n<fragment>\n\t<set-variable name=\"environment\" value=\"@(context.Request.Headers.GetValueOrDefault("Environment", "{{DefaultD365FOEnvironment}}"))\" />\n</fragment>",
"_1._5": "<!--\n IMPORTANT:\n - <inbound> fragment\n - Requires the environment variable. Best used in combination with SetEnvironmentVariable fragment.\n - Also requires the following named values\n - {{TenantId}}\n - {{D365FOClientId}}\n - {{D365FOClientSecret}}\n-->\n<fragment>\n\t<!-- Fetch token from cache -->\n\t<cache-lookup-value key=\"@((string)context.Variables["environment"] + "-token-{{D365FOClientId}}")\" variable-name=\"bearerToken\" />\n\t<choose>\n\t\t<!-- When a bearerToken is not available in cache -->\n\t\t<when condition=\"@(!context.Variables.ContainsKey("bearerToken"))\">\n\t\t\t<send-request mode=\"new\" response-variable-name=\"oauthResponse\" timeout=\"20\" ignore-error=\"false\">\n\t\t\t\t<set-url>https://login.microsoftonline.com/{{TenantId}}/oauth2/token</set-url>\n\t\t\t\t<set-method>POST</set-method>\n\t\t\t\t<set-header name=\"Content-Type\" exists-action=\"override\">\n\t\t\t\t\t<value>application/x-www-form-urlencoded</value>\n\t\t\t\t</set-header>\n\t\t\t\t<set-body>@{ \n return \"client_id={{D365FOClientId}}&resource=\" + \n context.Variables.GetValueOrDefault<string>(\"environment\") + \n \"&client_secret={{D365FOClientSecret}}&grant_type=client_credentials\"; \n }</set-body>\n\t\t\t</send-request>\n\t\t\t<!-- Store result in cache -->\n\t\t\t<set-variable name=\"accessToken\" value=\"@((string)((IResponse)context.Variables["oauthResponse"]).Body.As<JObject>()["access_token"])\" />\n\t\t\t<cache-store-value key=\"@((string)context.Variables["environment"] + "-token-{{D365FOClientId}}")\" value=\"@((string)context.Variables["accessToken"])\" duration=\"1200\" />\n\t\t\t<set-header name=\"Authorization\" exists-action=\"override\">\n\t\t\t\t<value>@(\"bearer \" + (string)context.Variables[\"accessToken\"])</value>\n\t\t\t</set-header>\n\t\t</when>\n\t\t<!-- If cache value exists -->\n\t\t<otherwise>\n\t\t\t<set-header name=\"Authorization\" exists-action=\"override\">\n\t\t\t\t<value>@(\"bearer \" + (string)context.Variables[\"bearerToken\"])</value>\n\t\t\t</set-header>\n\t\t</otherwise>\n\t</choose>\n</fragment>",
"_1._6": "<!--\n IMPORTANT:\n - <inbound> fragment\n - Requires the environment variable. Should be used in combination with the SetEnvironmentVariable fragment.\n-->\n<fragment>\n\t<set-backend-service base-url=\"@(context.Variables.GetValueOrDefault<string>("environment"))\" />\n</fragment>",
"_1._7": "<!--\n - <inbound> fragment\n-->\n<fragment>\n\t<!-- Serialize headers with line breaks -->\n\t<set-variable name=\"allHeaders\" value=\"@{\n\t\treturn string.Join(\n\t\t\t"\\n",\n\t\t\tcontext.Request.Headers\n\t\t\t\t.Where(h => h.Key != "Authorization" && h.Key != "Ocp-Apim-Subscription-Key")\n\t\t\t\t.Select(h => h.Key + ": " + string.Join(", ", h.Value))\n\t\t);\n\t}\" />\n\t<!-- Output to trace -->\n\t<trace source=\"log-all-headers\" severity=\"information\">\n @{\n return \"Request Headers:\\n\" + context.Variables[\"allHeaders\"];\n }\n </trace>\n</fragment>",
"_1.AddCrossCompanyParameterFragment": {
"name": "AddCrossCompanyParameter",
"value": "[variables('_1._2')]",
"description": "Adds the cross-company=true parameter to all requests."
},
"_1.fragments": [
"[variables('_1.AddCrossCompanyParameterFragment')]",
"[variables('_1.RetryOn429StatusCodeFragment')]",
"[variables('_1.SetEnvironmentVariableFragment')]",
"[variables('_1.SetMicrosoftOAuthorizationHeaderCachedFragment')]",
"[variables('_1.SetServiceBackendBasedOnEnvironmentVariableFragment')]",
"[variables('_1.LogHeadersFragment')]"
],
"_1.LogHeadersFragment": {
"name": "LogHeaders",
"value": "[variables('_1._7')]",
"description": "Logs all incoming request headers for debugging purposes."
},
"_1.RetryOn429StatusCodeFragment": {
"name": "RetryOn429StatusCode",
"value": "[variables('_1._3')]",
"description": "On status code 429 (Too Many Requests), retries the request 3 times with a delay of 10 seconds."
},
"_1.SetEnvironmentVariableFragment": {
"name": "SetEnvironmentVariable",
"value": "[variables('_1._4')]",
"description": "Sets the variable \"environment\". The value is either taken from the \"Environment\" request header or from the DefaultD365FOEnvironment named value."
},
"_1.SetMicrosoftOAuthorizationHeaderCachedFragment": {
"name": "SetMicrosoftOAuthorizationHeaderCached",
"value": "[variables('_1._5')]",
"description": "Gets an OAuth token to authorize requests to the D365FO environment. The token is requested based on the D365FOClientId, D365FOClientSecret and TenantId named values. The token is cached for 20 minutes."
},
"_1.SetServiceBackendBasedOnEnvironmentVariableFragment": {
"name": "SetServiceBackendBasedOnEnvironmentVariable",
"value": "[variables('_1._6')]",
"description": "Sets the backend service based on the \"environment\" variable. The variable is set by the SetEnvironmentVariableFragment."
}
},
"resources": {
"apiManagement": {
"type": "Microsoft.ApiManagement/service",
"apiVersion": "2024-05-01",
"name": "[format('D365FOAPIManagement-{0}', take(uniqueString(tenant().tenantId, resourceGroup().id), 5))]",
"location": "[resourceGroup().location]",
"sku": {
"name": "Consumption",
"capacity": 0
},
"properties": {
"publisherEmail": "[deployer().userPrincipalName]",
"publisherName": "[tenant().displayName]"
}
},
"d365FOUrlNamedValue": {
"type": "Microsoft.ApiManagement/service/namedValues",
"apiVersion": "2024-05-01",
"name": "[format('{0}/{1}', format('D365FOAPIManagement-{0}', take(uniqueString(tenant().tenantId, resourceGroup().id), 5)), 'DefaultD365FOEnvironment')]",
"properties": {
"displayName": "DefaultD365FOEnvironment",
"value": "[parameters('d365FOEnvironmentUrl')]"
},
"dependsOn": [
"apiManagement"
]
},
"clientIdNamedValue": {
"type": "Microsoft.ApiManagement/service/namedValues",
"apiVersion": "2024-05-01",
"name": "[format('{0}/{1}', format('D365FOAPIManagement-{0}', take(uniqueString(tenant().tenantId, resourceGroup().id), 5)), 'D365FOClientId')]",
"properties": {
"displayName": "D365FOClientId",
"value": "[parameters('clientId')]"
},
"dependsOn": [
"apiManagement"
]
},
"clientSecretNamedValue": {
"type": "Microsoft.ApiManagement/service/namedValues",
"apiVersion": "2024-05-01",
"name": "[format('{0}/{1}', format('D365FOAPIManagement-{0}', take(uniqueString(tenant().tenantId, resourceGroup().id), 5)), 'D365FOClientSecret')]",
"properties": {
"displayName": "D365FOClientSecret",
"secret": true,
"value": "[parameters('clientSecret')]"
},
"dependsOn": [
"apiManagement"
]
},
"tenantNamedValue": {
"type": "Microsoft.ApiManagement/service/namedValues",
"apiVersion": "2024-05-01",
"name": "[format('{0}/{1}', format('D365FOAPIManagement-{0}', take(uniqueString(tenant().tenantId, resourceGroup().id), 5)), 'TenantId')]",
"properties": {
"displayName": "TenantId",
"value": "[parameters('tenantId')]"
},
"dependsOn": [
"apiManagement"
]
},
"policyFragmentsResources": {
"copy": {
"name": "policyFragmentsResources",
"count": "[length(variables('policyFragments'))]"
},
"type": "Microsoft.ApiManagement/service/policyFragments",
"apiVersion": "2024-05-01",
"name": "[format('{0}/{1}', format('D365FOAPIManagement-{0}', take(uniqueString(tenant().tenantId, resourceGroup().id), 5)), variables('policyFragments')[copyIndex()].name)]",
"properties": {
"value": "[variables('policyFragments')[copyIndex()].value]",
"description": "[variables('policyFragments')[copyIndex()].description]"
},
"dependsOn": [
"apiManagement",
"clientIdNamedValue",
"clientSecretNamedValue",
"d365FOUrlNamedValue",
"tenantNamedValue"
]
},
"d365foApi": {
"type": "Microsoft.ApiManagement/service/apis",
"apiVersion": "2024-05-01",
"name": "[format('{0}/{1}', format('D365FOAPIManagement-{0}', take(uniqueString(tenant().tenantId, resourceGroup().id), 5)), 'D365FOAPI')]",
"properties": {
"displayName": "D365FO API",
"format": "openapi",
"value": "[variables('$fxv#0')]",
"path": "/d365fo",
"protocols": [
"https"
]
},
"dependsOn": [
"apiManagement"
]
},
"d365foApiPolicy": {
"type": "Microsoft.ApiManagement/service/apis/policies",
"apiVersion": "2024-05-01",
"name": "[format('{0}/{1}/{2}', format('D365FOAPIManagement-{0}', take(uniqueString(tenant().tenantId, resourceGroup().id), 5)), 'D365FOAPI', 'policy')]",
"properties": {
"value": "[variables('$fxv#1')]"
},
"dependsOn": [
"d365foApi",
"policyFragmentsResources"
]
},
"secretNamedValueAppInsights": {
"type": "Microsoft.ApiManagement/service/namedValues",
"apiVersion": "2024-05-01",
"name": "[format('{0}/{1}', format('D365FOAPIManagement-{0}', take(uniqueString(tenant().tenantId, resourceGroup().id), 5)), variables('appInsightsInstrumentationKeyNamedValueName'))]",
"properties": {
"displayName": "[variables('appInsightsInstrumentationKeyNamedValueName')]",
"secret": true,
"value": "[listOutputsWithSecureValues('appInsights', '2022-09-01').applicationInsightsInstrumentationKey]"
},
"dependsOn": [
"apiManagement",
"appInsights"
]
},
"apimLogger": {
"type": "Microsoft.ApiManagement/service/loggers",
"apiVersion": "2024-05-01",
"name": "[format('{0}/{1}', format('D365FOAPIManagement-{0}', take(uniqueString(tenant().tenantId, resourceGroup().id), 5)), variables('applicationInsightsName'))]",
"properties": {
"loggerType": "applicationInsights",
"isBuffered": true,
"credentials": {
"instrumentationKey": "[format('{{{{{0}}}}}', variables('appInsightsInstrumentationKeyNamedValueName'))]"
}
},
"dependsOn": [
"apiManagement",
"secretNamedValueAppInsights"
]
},
"d365foApiDiagnostics": {
"type": "Microsoft.ApiManagement/service/apis/diagnostics",
"apiVersion": "2024-05-01",
"name": "[format('{0}/{1}/{2}', format('D365FOAPIManagement-{0}', take(uniqueString(tenant().tenantId, resourceGroup().id), 5)), 'D365FOAPI', 'applicationinsights')]",
"properties": {
"loggerId": "[resourceId('Microsoft.ApiManagement/service/loggers', format('D365FOAPIManagement-{0}', take(uniqueString(tenant().tenantId, resourceGroup().id), 5)), variables('applicationInsightsName'))]",
"alwaysLog": "allErrors",
"logClientIp": true,
"sampling": {
"samplingType": "fixed",
"percentage": 100
},
"frontend": "[variables('logSettings')]",
"backend": "[variables('logSettings')]"
},
"dependsOn": [
"apimLogger",
"d365foApi"
]
},
"apimServiceDiagnostics": {
"type": "Microsoft.Insights/diagnosticSettings",
"apiVersion": "2021-05-01-preview",
"scope": "[format('Microsoft.ApiManagement/service/{0}', format('D365FOAPIManagement-{0}', take(uniqueString(tenant().tenantId, resourceGroup().id), 5)))]",
"name": "APIMAnalytics",
"properties": {
"workspaceId": "[reference('appInsights').outputs.logAnalyticsWorkspaceId.value]",
"logs": [
{
"category": "GatewayLogs",
"enabled": true
}
],
"metrics": [
{
"category": "AllMetrics",
"enabled": true
}
]
},
"dependsOn": [
"apiManagement",
"appInsights"
]
},
"appInsights": {
"type": "Microsoft.Resources/deployments",
"apiVersion": "2022-09-01",
"name": "D365FOAPIManagementMonitoring",
"properties": {
"expressionEvaluationOptions": {
"scope": "inner"
},
"mode": "Incremental",
"parameters": {
"applicationInsightsName": {
"value": "[variables('applicationInsightsName')]"
}
},
"template": {
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"languageVersion": "2.0",
"contentVersion": "1.0.0.0",
"metadata": {
"_generator": {
"name": "bicep",
"version": "0.37.4.10188",
"templateHash": "11847530913114245845"
}
},
"parameters": {
"location": {
"type": "string",
"defaultValue": "[resourceGroup().location]",
"metadata": {
"description": "Specifies the location in which the Azure Storage resources should be deployed."
}
},
"applicationInsightsName": {
"type": "string",
"defaultValue": "[format('appInsigths{0}', uniqueString(resourceGroup().id))]",
"metadata": {
"description": "Specifies the name of the Applications Insights resource."
}
},
"logAnalyticsWorkspaceName": {
"type": "string",
"defaultValue": "[format('logAnalytics{0}', uniqueString(resourceGroup().id))]",
"metadata": {
"description": "Specifies the name of the Log Analytics Workspace resource."
}
}
},
"resources": {
"logAnalyticsWorkspace": {
"type": "Microsoft.OperationalInsights/workspaces",
"apiVersion": "2023-09-01",
"name": "[parameters('logAnalyticsWorkspaceName')]",
"location": "[parameters('location')]",
"properties": {
"sku": {
"name": "PerGB2018"
}
}
},
"appInsights": {
"type": "Microsoft.Insights/components",
"apiVersion": "2020-02-02",
"name": "[parameters('applicationInsightsName')]",
"location": "[parameters('location')]",
"kind": "web",
"properties": {
"Application_Type": "web",
"WorkspaceResourceId": "[resourceId('Microsoft.OperationalInsights/workspaces', parameters('logAnalyticsWorkspaceName'))]"
},
"dependsOn": [
"logAnalyticsWorkspace"
]
}
},
"outputs": {
"applicationInsightsName": {
"type": "string",
"value": "[parameters('applicationInsightsName')]"
},
"applicationInsightsInstrumentationKey": {
"type": "securestring",
"value": "[reference('appInsights').InstrumentationKey]"
},
"logAnalyticsWorkspaceId": {
"type": "string",
"value": "[resourceId('Microsoft.OperationalInsights/workspaces', parameters('logAnalyticsWorkspaceName'))]"
}
}
}
}
}
}
}