Skip to content

Commit 02a6b2e

Browse files
committed
fix: update APIM module path and adjust resource group naming conventions
1 parent 891444f commit 02a6b2e

3 files changed

Lines changed: 179 additions & 4 deletions

File tree

labs/mcp-prm-oauth/main.bicep

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ module appInsightsModule '../../modules/monitor/v1/appinsights.bicep' = {
6060
}
6161

6262
// 3. API Management
63-
module apimModule '../../modules/apim/v3/apim.bicep' = {
63+
module apimModule '../../modules/apim/v4/apim.bicep' = {
6464
name: 'apimModule'
6565
params: {
6666
apimSku: apimSku

labs/mcp-prm-oauth/mcp-prm-oauth.ipynb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
"import utils\n",
5757
"\n",
5858
"deployment_name = os.path.basename(os.path.dirname(globals()['__vsc_ipynb_file__']))\n",
59-
"resource_group_name = f\"lab-{deployment_name}\" # change the name to match your naming style\n",
59+
"resource_group_name = f\"lab-{deployment_name}-1\" # change the name to match your naming style\n",
6060
"resource_group_location = \"ukwest\"\n",
6161
"\n",
6262
"aiservices_config = []\n",
@@ -71,7 +71,7 @@
7171
"inference_api_version = \"2025-03-01-preview\"\n",
7272
"foundry_project_name = deployment_name\n",
7373
"\n",
74-
"app_registration_name = f\"lab-{deployment_name}-app\"\n",
74+
"app_registration_name = f\"lab-{deployment_name}-app1\"\n",
7575
"\n",
7676
"build = 0\n",
7777
"prm_mcp_server_image = \"mcp-prm-server\"\n",
@@ -335,7 +335,7 @@
335335
"name": "python",
336336
"nbconvert_exporter": "python",
337337
"pygments_lexer": "ipython3",
338-
"version": "3.12.-1"
338+
"version": "3.12.13"
339339
}
340340
},
341341
"nbformat": 4,

modules/apim/v4/apim.bicep

Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
/**
2+
* @module apim-v1 (v.2025-09-01-preview)
3+
* @description This module defines the Azure API Management (APIM) resources using Bicep.
4+
* It includes configurations for creating and managing APIM instance.
5+
* This is version 1 (v1) of the APIM Bicep module.
6+
*/
7+
8+
// ------------------
9+
// PARAMETERS
10+
// ------------------
11+
12+
@description('The suffix to append to the API Management instance name. Defaults to a unique string based on subscription and resource group IDs.')
13+
param resourceSuffix string = uniqueString(subscription().id, resourceGroup().id)
14+
15+
@description('The name of the API Management instance. Defaults to "apim-<resourceSuffix>".')
16+
param apiManagementName string = 'apim-${resourceSuffix}'
17+
18+
@description('The location of the API Management instance. Defaults to the resource group location.')
19+
param location string = resourceGroup().location
20+
21+
@description('The email address of the publisher. Defaults to "noreply@microsoft.com".')
22+
param publisherEmail string = 'noreply@microsoft.com'
23+
24+
@description('The name of the publisher. Defaults to "Microsoft".')
25+
param publisherName string = 'Microsoft'
26+
27+
@description('The pricing tier of this API Management service')
28+
@allowed([
29+
'Consumption'
30+
'Developer'
31+
'Basic'
32+
'Basicv2'
33+
'Standard'
34+
'Standardv2'
35+
'Premium'
36+
])
37+
param apimSku string = 'Basicv2'
38+
39+
@description('The type of managed identity to by used with API Management')
40+
@allowed([
41+
'SystemAssigned'
42+
'UserAssigned'
43+
'SystemAssigned, UserAssigned'
44+
])
45+
param apimManagedIdentityType string = 'SystemAssigned'
46+
47+
@description('The user-assigned managed identity ID to be used with API Management')
48+
param apimUserAssignedManagedIdentityId string = ''
49+
50+
@description('Configuration array for APIM subscriptions')
51+
param apimSubscriptionsConfig array = []
52+
53+
@description('The Log Analytics Workspace ID for diagnostic settings')
54+
param lawId string = ''
55+
56+
@description('The instrumentation key for Application Insights')
57+
param appInsightsInstrumentationKey string = ''
58+
59+
@description('The resource ID for Application Insights')
60+
param appInsightsId string = ''
61+
62+
@description('The release channel for the API Management service')
63+
@allowed([
64+
'Early'
65+
'Default'
66+
'Late'
67+
'GenAI'
68+
])
69+
param releaseChannel string = 'Default'
70+
71+
// ------------------
72+
// VARIABLES
73+
// ------------------
74+
75+
76+
// ------------------
77+
// RESOURCES
78+
// ------------------
79+
80+
// https://learn.microsoft.com/azure/templates/microsoft.apimanagement/service
81+
resource apimService 'Microsoft.ApiManagement/service@2025-09-01-preview' = {
82+
name: apiManagementName
83+
location: location
84+
sku: {
85+
name: apimSku
86+
capacity: 1
87+
}
88+
properties: {
89+
publisherEmail: publisherEmail
90+
publisherName: publisherName
91+
releaseChannel: releaseChannel
92+
}
93+
identity: {
94+
type: apimManagedIdentityType
95+
userAssignedIdentities: apimManagedIdentityType == 'UserAssigned' && apimUserAssignedManagedIdentityId != '' ? {
96+
// BCP037: Not yet added to latest API:
97+
'${apimUserAssignedManagedIdentityId}': {}
98+
} : null
99+
}
100+
}
101+
102+
resource apimDiagnosticSettings 'Microsoft.Insights/diagnosticSettings@2021-05-01-preview' = if(length(lawId) > 0) {
103+
scope: apimService
104+
name: 'apimDiagnosticSettings'
105+
properties: {
106+
workspaceId: lawId
107+
logAnalyticsDestinationType: 'Dedicated'
108+
logs: [
109+
{
110+
categoryGroup: 'AllLogs'
111+
enabled: true
112+
}
113+
]
114+
metrics: [
115+
{
116+
category: 'AllMetrics'
117+
enabled: true
118+
}
119+
]
120+
}
121+
}
122+
123+
resource apimLogger 'Microsoft.ApiManagement/service/loggers@2025-09-01-preview' = if(length(lawId) > 0) {
124+
parent: apimService
125+
name: 'azuremonitor'
126+
properties: {
127+
loggerType: 'azureMonitor'
128+
isBuffered: false // Set to false to ensure logs are sent immediately
129+
}
130+
}
131+
132+
// Create a logger only if we have an App Insights ID and instrumentation key.
133+
resource apimAppInsightsLogger 'Microsoft.ApiManagement/service/loggers@2025-09-01-preview' = if (!empty(appInsightsId) && !empty(appInsightsInstrumentationKey)) {
134+
name: 'appinsights-logger'
135+
parent: apimService
136+
properties: {
137+
credentials: {
138+
instrumentationKey: appInsightsInstrumentationKey
139+
}
140+
description: 'APIM Logger for Application Insights'
141+
isBuffered: false
142+
loggerType: 'applicationInsights'
143+
resourceId: appInsightsId
144+
}
145+
}
146+
147+
@batchSize(1)
148+
resource apimSubscription 'Microsoft.ApiManagement/service/subscriptions@2025-09-01-preview' = [for subscription in apimSubscriptionsConfig: if(length(apimSubscriptionsConfig) > 0) {
149+
name: subscription.name
150+
parent: apimService
151+
properties: {
152+
allowTracing: true
153+
displayName: '${subscription.displayName}'
154+
scope: '/apis'
155+
state: 'active'
156+
}
157+
}]
158+
159+
160+
// ------------------
161+
// OUTPUTS
162+
// ------------------
163+
164+
output id string = apimService.id
165+
output name string = apimService.name
166+
output principalId string = (apimManagedIdentityType == 'SystemAssigned') ? apimService.identity.principalId : ''
167+
output gatewayUrl string = apimService.properties.gatewayUrl
168+
output loggerId string = (length(lawId) > 0) ? apimLogger.id : ''
169+
170+
#disable-next-line outputs-should-not-contain-secrets
171+
output apimSubscriptions array = [for (subscription, i) in apimSubscriptionsConfig: {
172+
name: subscription.name
173+
displayName: subscription.displayName
174+
key: apimSubscription[i].listSecrets().primaryKey
175+
}]

0 commit comments

Comments
 (0)