-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfn.bicep
124 lines (107 loc) · 2.83 KB
/
fn.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
//
// Deploys an Azure Functions app
// https://learn.microsoft.com/en-us/azure/azure-functions/
//
@description('Descriptor for this resource')
param prefix string = 'fn'
@description('Unique suffix for all resources in this deployment')
param suffix string = uniqueString(resourceGroup().id)
@description('Location for all resources.')
param location string = resourceGroup().location
@description('Hosting plan SKU.')
param sku string = 'Y1'
@description('Hosting plan tier.')
param tier string = 'Dynamic'
@description('The language worker runtime to load in the function app.')
@allowed([
'node'
'dotnet'
'dotnet-isolated'
'java'
'powershell'
'python'
'custom'
])
param fnRuntime string = 'dotnet-isolated'
@description('Name of required storage resource')
param storageName string
@description('Optional application settings environment vars')
param configuration array = []
resource hostingPlan 'Microsoft.Web/serverfarms@2023-12-01' = {
name: 'farm-${suffix}'
location: location
sku: {
name: sku
tier: tier
}
}
// Retrieve needed details out of storage resource
resource storage 'Microsoft.Storage/storageAccounts@2023-05-01' existing = {
name: storageName
}
var storcstr = 'DefaultEndpointsProtocol=https;AccountName=${storage.name};EndpointSuffix=${environment().suffixes.storage};AccountKey=${storage.listKeys().keys[0].value}'
var functionAppName = toLower('${prefix}-${suffix}')
// Set standard app settings
// https://learn.microsoft.com/en-us/azure/azure-functions/functions-app-settings
var appsettings = concat(
[
{
name: 'AzureWebJobsStorage'
value: storcstr
}
{
name: 'WEBSITE_CONTENTAZUREFILECONNECTIONSTRING'
value: storcstr
}
{
name: 'WEBSITE_CONTENTSHARE'
value: functionAppName
}
{
name: 'FUNCTIONS_EXTENSION_VERSION'
value: '~4'
}
{
name: 'APPINSIGHTS_INSTRUMENTATIONKEY'
value: applicationInsights.properties.InstrumentationKey
}
{
name: 'FUNCTIONS_WORKER_RUNTIME'
value: fnRuntime
}
],
configuration
)
resource functionApp 'Microsoft.Web/sites@2022-03-01' = {
name: functionAppName
location: location
kind: 'functionapp'
identity: {
type: 'SystemAssigned'
}
properties: {
serverFarmId: hostingPlan.id
siteConfig: {
appSettings: appsettings
ftpsState: 'FtpsOnly'
minTlsVersion: '1.2'
}
httpsOnly: true
}
}
resource applicationInsights 'Microsoft.Insights/components@2020-02-02' = {
name: 'insight-${suffix}'
location: location
kind: 'web'
properties: {
Application_Type: 'web'
Request_Source: 'rest'
}
}
output result object = {
name: functionApp.name
id: functionApp.id
principal: functionApp.identity.principalId
}
output principal string = functionApp.identity.principalId
output functionAppName string = functionApp.name