-
Notifications
You must be signed in to change notification settings - Fork 4
/
apim.bicep
111 lines (93 loc) · 3.27 KB
/
apim.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
//Automation Note: APIM has softdelete protection on by default. You need to explicitly delete, if redeploying with the same name. az rest --method delete --header "Accept=applicaiton/json" -u 'https://management.azure.com/subscriptions/{subId}/providers/Microsoft.ApiManagement/locations/{region}/deletedservices/{apim}?api-version=2020-06-01-preview'
@description('Used in the naming of Az resources')
@minLength(3)
param nameSeed string
@description('Azure region where the resources will be deployed')
param location string = resourceGroup().location
@description('The name of the owner of the service')
@minLength(1)
param publisherName string = 'Gobyers'
@description('The pricing tier of this API Management service')
@allowed([
'Developer'
'Premium'
'Consumption'
])
param sku string = 'Consumption'
param useRedisCache bool = true
@description('The email address of the owner of the service')
@minLength(1)
param publisherEmail string = '[email protected]'
@description('The instance size of this API Management service.This should be in multiple of zones getting deployed.')
param skuCount int = 1
@description('Zone numbers e.g. 1,2,3.')
param availabilityZones array = [
'1'
'2'
'3'
]
param AppInsightsName string = ''
var apiManagementServiceName = 'apim-${nameSeed}-${substring(sku,0,3)}-${uniqueString(resourceGroup().id, nameSeed)}'
resource apim 'Microsoft.ApiManagement/service@2021-04-01-preview' = {
name: apiManagementServiceName
location: location
sku: {
name: sku
capacity: sku=='Consumption' ? 0 : skuCount
}
zones: ((length(availabilityZones) == 0 || sku!='Premium') ? json('null') : availabilityZones)
identity: {
type: 'UserAssigned'
userAssignedIdentities: {
'${apiUai.id}': {}
}
}
properties: {
publisherEmail: publisherEmail
publisherName: publisherName
}
}
output ApimName string = apim.name
resource apimPolicy 'Microsoft.ApiManagement/service/policies@2019-12-01' = {
name: '${apim.name}/policy'
properties:{
format: 'rawxml'
value: '<policies><inbound /><backend><forward-request /></backend><outbound /><on-error /></policies>'
}
}
resource apiUai 'Microsoft.ManagedIdentity/userAssignedIdentities@2018-11-30' = {
name: 'id-apim-${nameSeed}'
location: location
}
output apimUaiName string = apiUai.name
resource AppInsights 'Microsoft.Insights/components@2020-02-02' existing = if(!empty(AppInsightsName)) {
name: AppInsightsName
}
module redis 'redis.bicep' = if(useRedisCache) {
name: 'apim-redis'
params: {
nameSeed: nameSeed
}
}
resource apimcache 'Microsoft.ApiManagement/service/caches@2021-04-01-preview' = if(useRedisCache) {
name: resourceGroup().location
parent: apim
properties: {
connectionString: redis.outputs.redisconnectionstring
useFromLocation: resourceGroup().location
description: redis.outputs.redishostnmame
resourceId: redis.outputs.redisfullresourceid
}
}
// Create Logger and link logger
resource apimLogger 'Microsoft.ApiManagement/service/loggers@2019-12-01' = {
name: '${apim.name}/${apim.name}-logger'
properties:{
resourceId: AppInsights.id
loggerType: 'applicationInsights'
credentials:{
instrumentationKey: AppInsights.properties.InstrumentationKey
}
description: 'APIM logger for Application Insights'
}
}