This repository has been archived by the owner on Jul 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmemfault-integration.bicep
167 lines (152 loc) · 4.99 KB
/
memfault-integration.bicep
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
@description('Specifies the name of the nRF Asset Tracker for Azure app')
@minLength(3)
param appName string = 'nrfassettracker'
@description('Specifies the storage account name to use, which is globally unique.')
@minLength(3)
param storageAccountName string = appName
@description('Location for all resources.')
param location string = resourceGroup().location
@description('The name of the IoT hub consumer group to user for Memfault messages')
@minLength(3)
param memfaultIotEventsConsumerGroupName string = 'memfault'
@description('Specifies the name of the key vault')
@minLength(3)
param keyVaultName string = 'assetTracker'
var keyVaultSecretsUser = subscriptionResourceId('Microsoft.Authorization/roleDefinitions', '4633458b-17de-408a-b874-0445c86b69e6')
var managedIdentity = '${appName}-memfault-integration-functionapp-identity'
resource iotHub 'Microsoft.Devices/IotHubs@2021-07-02' existing = {
name: '${appName}IotHub'
}
resource consumerGroup 'Microsoft.Devices/iotHubs/eventhubEndpoints/ConsumerGroups@2020-03-01' = {
name: '${appName}IotHub/events/${memfaultIotEventsConsumerGroupName}'
}
resource storageAccount 'Microsoft.Storage/storageAccounts@2019-06-01' = {
name: storageAccountName
location: location
sku: {
name: 'Standard_LRS'
}
kind: 'StorageV2'
properties: {
supportsHttpsTrafficOnly: true
}
}
resource serverFarm 'Microsoft.Web/serverfarms@2022-09-01' = {
name: '${storageAccountName}Serverfarm'
location: location
sku: {
name: 'Y1'
tier: 'Dynamic'
}
properties: {
}
}
resource appIdentity 'Microsoft.ManagedIdentity/userAssignedIdentities@2018-11-30'= {
name: managedIdentity
location: location
}
resource functionApp 'Microsoft.Web/sites@2022-09-01' = {
name: '${appName}-memfault-integration'
location: location
kind: 'functionapp'
identity: {
type: 'SystemAssigned, UserAssigned'
userAssignedIdentities: {
'${resourceId('Microsoft.ManagedIdentity/userAssignedIdentities', managedIdentity)}': {}
}
}
properties: {
serverFarmId: serverFarm.id
siteConfig: {
appSettings: [
{
name: 'AzureWebJobsStorage'
value: 'DefaultEndpointsProtocol=https;AccountName=${storageAccount.name};EndpointSuffix=${environment().suffixes.storage};AccountKey=${storageAccount.listKeys().keys[0].value}'
}
{
name: 'WEBSITE_CONTENTAZUREFILECONNECTIONSTRING'
value: 'DefaultEndpointsProtocol=https;AccountName=${storageAccount.name};EndpointSuffix=${environment().suffixes.storage};AccountKey=${storageAccount.listKeys().keys[0].value}'
}
{
name: 'FUNCTIONS_EXTENSION_VERSION'
value: '~4'
}
{
name: 'FUNCTIONS_WORKER_RUNTIME'
value: 'node'
}
{
name: 'WEBSITE_NODE_DEFAULT_VERSION'
value: '~16'
}
{
name: 'WEBSITE_RUN_FROM_PACKAGE'
value: '1'
}
{
name: 'STORAGE_ACCESS_KEY'
value: storageAccount.listKeys().keys[0].value
}
{
name: 'STORAGE_ACCOUNT_NAME'
value: storageAccountName
}
{
name: 'APPINSIGHTS_INSTRUMENTATIONKEY'
value: applicationInsights.properties.InstrumentationKey
}
{
name: 'MEMFAULT_IOT_EVENTS_CONSUMER_GROUP_NAME'
value: memfaultIotEventsConsumerGroupName
}
{
name: 'IOTHUB_EVENTS_EVENT_HUB_NAME'
value: iotHub.properties.eventHubEndpoints.events.path
}
{
name: 'IOTHUB_EVENTS_CONNECTION_STRING'
value: 'Endpoint=${iotHub.properties.eventHubEndpoints.events.endpoint};SharedAccessKeyName=iothubowner;SharedAccessKey=${iotHub.listkeys().value[0].primaryKey};EntityPath=${iotHub.properties.eventHubEndpoints.events.path}'
}
{
name: 'KEYVAULT_NAME'
value: keyVaultName
}
{
name: 'AZURE_CLIENT_ID'
value: reference(resourceId('Microsoft.ManagedIdentity/userAssignedIdentities', managedIdentity)).clientId
}
]
use32BitWorkerProcess: false
cors: {
allowedOrigins: [
'*'
]
supportCredentials: false
}
http20Enabled: true
ftpsState: 'Disabled'
}
httpsOnly: true
}
}
resource applicationInsights 'microsoft.insights/components@2020-02-02' = {
name: '${storageAccountName}Insights'
location: location
kind: 'web'
properties: {
Application_Type: 'web'
Request_Source: 'rest'
}
}
resource keyVault 'Microsoft.KeyVault/vaults@2023-02-01' existing = {
name: keyVaultName
}
resource keyVaultPermission 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
name: guid('Key Vault Secret User', appName , subscription().subscriptionId)
properties: {
roleDefinitionId: keyVaultSecretsUser
principalId: reference(resourceId('Microsoft.ManagedIdentity/userAssignedIdentities', managedIdentity), '2018-11-30').principalId
principalType: 'ServicePrincipal'
}
scope: keyVault
}