-
Notifications
You must be signed in to change notification settings - Fork 68
Expand file tree
/
Copy pathapi.bicep
More file actions
112 lines (101 loc) · 3.97 KB
/
api.bicep
File metadata and controls
112 lines (101 loc) · 3.97 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
param name string
@description('Primary location for all resources & Flex Consumption Function App')
param location string = resourceGroup().location
param tags object = {}
param applicationInsightsName string = ''
param appServicePlanId string
param appSettings object = {}
param runtimeName string
param runtimeVersion string
param serviceName string = 'api'
param storageAccountName string
param deploymentStorageContainerName string
param virtualNetworkSubnetId string = ''
param instanceMemoryMB int = 2048
param maximumInstanceCount int = 100
param identityId string = ''
param identityClientId string = ''
param enableBlob bool = true
param enableQueue bool = false
param enableTable bool = false
param enableFile bool = false
@allowed(['SystemAssigned', 'UserAssigned'])
param identityType string = 'UserAssigned'
var applicationInsightsIdentity = 'ClientId=${identityClientId};Authorization=AAD'
var kind = 'functionapp,linux'
// Create base application settings
var baseAppSettings = {
// Only include required credential settings unconditionally
AzureWebJobsStorage__credential: 'managedidentity'
AzureWebJobsStorage__clientId: identityClientId
// Application Insights settings are always included
APPLICATIONINSIGHTS_AUTHENTICATION_STRING: applicationInsightsIdentity
APPLICATIONINSIGHTS_CONNECTION_STRING: applicationInsights.properties.ConnectionString
// Required for MCP decorators (azure-functions 1.25.0b2+)
PYTHON_ISOLATE_WORKER_DEPENDENCIES: '1'
}
// Dynamically build storage endpoint settings based on feature flags
var blobSettings = enableBlob ? { AzureWebJobsStorage__blobServiceUri: stg.properties.primaryEndpoints.blob } : {}
var queueSettings = enableQueue ? { AzureWebJobsStorage__queueServiceUri: stg.properties.primaryEndpoints.queue } : {}
var tableSettings = enableTable ? { AzureWebJobsStorage__tableServiceUri: stg.properties.primaryEndpoints.table } : {}
var fileSettings = enableFile ? { AzureWebJobsStorage__fileServiceUri: stg.properties.primaryEndpoints.file } : {}
// Merge all app settings
var allAppSettings = union(
appSettings,
blobSettings,
queueSettings,
tableSettings,
fileSettings,
baseAppSettings
)
resource stg 'Microsoft.Storage/storageAccounts@2022-09-01' existing = {
name: storageAccountName
}
resource applicationInsights 'Microsoft.Insights/components@2020-02-02' existing = if (!empty(applicationInsightsName)) {
name: applicationInsightsName
}
// Create a Flex Consumption Function App to host the API
module api 'br/public:avm/res/web/site:0.15.1' = {
name: '${serviceName}-flex-consumption'
params: {
kind: kind
name: name
location: location
tags: union(tags, { 'azd-service-name': serviceName })
serverFarmResourceId: appServicePlanId
managedIdentities: {
systemAssigned: identityType == 'SystemAssigned'
userAssignedResourceIds: [
'${identityId}'
]
}
functionAppConfig: {
deployment: {
storage: {
type: 'blobContainer'
value: '${stg.properties.primaryEndpoints.blob}${deploymentStorageContainerName}'
authentication: {
type: identityType == 'SystemAssigned' ? 'SystemAssignedIdentity' : 'UserAssignedIdentity'
userAssignedIdentityResourceId: identityType == 'UserAssigned' ? identityId : ''
}
}
}
scaleAndConcurrency: {
instanceMemoryMB: instanceMemoryMB
maximumInstanceCount: maximumInstanceCount
}
runtime: {
name: runtimeName
version: runtimeVersion
}
}
siteConfig: {
alwaysOn: false
}
virtualNetworkSubnetId: !empty(virtualNetworkSubnetId) ? virtualNetworkSubnetId : null
appSettingsKeyValuePairs: allAppSettings
}
}
output SERVICE_API_NAME string = api.outputs.name
// Ensure output is always string, handle potential null from module output if SystemAssigned is not used
output SERVICE_API_IDENTITY_PRINCIPAL_ID string = identityType == 'SystemAssigned' ? api.outputs.?systemAssignedMIPrincipalId ?? '' : ''