apim-bicep
Skill100 starsChanged 17 months agoMITView on GitHub
Guide for building Bicep files for Azure API Management (APIM) and related Azure services. Use when users want to create, modify, or understand Bicep templates for APIM instances, APIs, backends, subscriptions, policies, products, loggers, and diagnostics. This skill provides Bicep syntax and patterns based on the shared modules in this repository.
We split this skill into the rules it gives an agent
3 rules. About 0 are common, 2 are distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈2
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 10
Do not add tool, module, CLI extension, container feature, or package installation that bypasses the repository's eight-day release waiting …
- Very specific: line 14
When this workflow creates or updates Markdown, follow .markdownlint.json and .github/markdown.instructions.md without flattening semantic …
- Distinctive: line 171
Run legacy diagnostic-setting migration before every infrastructure deployment, not only when an update flag is set.
≈ “Common” is an estimate: at least 1 in 5 of the 308,232 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
APIM Bicep
This skill provides guidance for creating Azure Bicep templates for API Management and related services.
Do not add tool, module, CLI extension, container feature, or package installation that bypasses the repository's eight-day release waiting period. Any new dependency must use an eligible exact version and the repository's guarded install flow.
MockAPI container images from simonkurtzmsft/mockapi are exempt from this waiting period. Keep an exact version tag and immutable digest; this exception does not apply to packages, tools, or GitHub Actions.
When this workflow creates or updates Markdown, follow .markdownlint.json and .github/markdown.instructions.md without flattening semantic structure. Before completion, run npx --no-install markdownlint-cli2 "**/*.md" "#**/.venv/**" "#**/node_modules/**" from the repository root and require zero violations.
Quick Start - Basic APIM Instance
@description('The name of the API Management service instance')
param apiManagementServiceName string = 'apim-${uniqueString(resourceGroup().id)}'
@description('The email address of the publisher')
param publisherEmail string
@description('The name of the publisher')
param publisherName string
@description('The pricing tier of this API Management service')
@allowed(['Consumption', 'Developer', 'Basic', 'Basicv2', 'Standard', 'Standardv2', 'Premium', 'Premiumv2'])
param sku string = 'Basicv2'
@description('Location for all resources')
param location string = resourceGroup().location
resource apimService 'Microsoft.ApiManagement/service@2024-06-01-preview' = {
name: apiManagementServiceName
location: location
sku: {
name: sku
capacity: 1
}
identity: {
type: 'SystemAssigned'
}
properties: {
publisherEmail: publisherEmail
publisherName: publisherName
}
}
output apimId string = apimService.id
output apimName string = apimService.name
output gatewayUrl string = apimService.properties.gatewayUrl
output principalId string = apimService.identity.principalIdResource Types Reference
| Resource Type | API Version | Purpose |
Microsoft.ApiManagement/service | 2024-06-01-preview | APIM service instance |
Microsoft.ApiManagement/service/apis | 2024-06-01-preview | API definitions |
Microsoft.ApiManagement/service/apis/operations | 2024-06-01-preview | API operations |
Microsoft.ApiManagement/service/apis/policies | 2024-06-01-preview | API-level policies |
Microsoft.ApiManagement/service/backends | 2024-06-01-preview | Backend services |
Microsoft.ApiManagement/service/subscriptions | 2024-06-01-preview | API subscriptions |
Microsoft.ApiManagement/service/products | 2024-06-01-preview | API products |
Microsoft.ApiManagement/service/loggers | 2024-06-01-preview | Logging configuration |
Microsoft.ApiManagement/service/apis/diagnostics | 2024-06-01-preview | API diagnostics |
Essential Patterns
Backend with Managed Identity
resource backend 'Microsoft.ApiManagement/service/backends@2024-06-01-preview' = {
name: 'my-backend'
parent: apimService
properties: {
description: 'Backend with managed identity auth'
url: 'https://my-service.azure.com'
protocol: 'http'
credentials: {
managedIdentity: {
resource: 'https://cognitiveservices.azure.com'
}
}
}
}Backend Pool (Load Balancing)
resource backendPool 'Microsoft.ApiManagement/service/backends@2024-06-01-preview' = {
name: 'inference-backend-pool'
parent: apimService
properties: {
description: 'Load balancer for multiple backends'
type: 'Pool'
pool: {
services: [for (config, i) in backendsConfig: {
id: '/backends/${backends[i].name}'
priority: config.?priority ?? 1
weight: config.?weight ?? 1
}]
}
}
}API with OpenAPI Spec
resource api 'Microsoft.ApiManagement/service/apis@2024-06-01-preview' = {
name: 'my-api'
parent: apimService
properties: {
displayName: 'My API'
description: 'API description'
path: 'api/v1'
protocols: ['https']
subscriptionRequired: true
subscriptionKeyParameterNames: {
header: 'api-key'
query: 'api-key'
}
format: 'openapi+json'
value: string(loadJsonContent('./openapi.json'))
}
}API Policy from File
resource apiPolicy 'Microsoft.ApiManagement/service/apis/policies@2024-06-01-preview' = {
name: 'policy'
parent: api
properties: {
format: 'rawxml'
value: loadTextContent('policy.xml')
}
}Subscription
@batchSize(1)
resource subscription 'Microsoft.ApiManagement/service/subscriptions@2024-06-01-preview' = [for sub in subscriptionsConfig: {
name: sub.name
parent: apimService
properties: {
displayName: sub.displayName
scope: '/apis' // or '/apis/{apiId}' or '/products/{productId}'
state: 'active'
allowTracing: true
}
}]Diagnostics and Logging
Diagnostic Setting Ownership
- Each infrastructure owns one canonical
apim-diagnosticssetting for its APIM service and Log Analytics workspace. - Enable
GatewayLogs,WebSocketConnectionLogs, andGatewayLlmLogsin that shared setting so samples can coexist without redefining category-to-sink mappings. - Samples that need the infrastructure workspace must reuse the canonical setting name. Do not create a sample-named setting for the same workspace and categories.
- A sample-specific diagnostic setting is valid only for a different sink, such as Event Hub. Keep that setting destination-specific so later baseline deployments cannot remove its configuration.
- Run legacy diagnostic-setting migration before every infrastructure deployment, not only when an update flag is set. Create and retry paths can target existing resources; test both paths and stop deployment if migration fails.
- Azure can restore orphaned diagnostic settings after a deleted APIM resource is recreated, when preflight discovery found nothing. After a failed infrastructure deployment, rerun migration and retry once only if it removed a legacy setting. Test reappearance after empty preflight, no-op recovery, migration failure, and the retry limit.
Azure Monitor Logger
resource apimLogger 'Microsoft.ApiManagement/service/loggers@2024-06-01-preview' = {
parent: apimService
name: 'azuremonitor'
properties: {
loggerType: 'azureMonitor'
isBuffered: false
}
}Application Insights Logger
resource appInsightsLogger 'Microsoft.ApiManagement/service/loggers@2024-06-01-preview' = {
name: 'appinsights-logger'
parent: apimService
properties: {
loggerType: 'applicationInsights'
credentials: {
instrumentationKey: appInsightsInstrumentationKey
}
description: 'APIM Logger for Application Insights'
isBuffered: false
resourceId: appInsightsId
}
}API Diagnostics with LLM Logging
resource apiDiagnostics 'Microsoft.ApiManagement/service/apis/diagnostics@2024-06-01-preview' = {
parent: api
name: 'azuremonitor'
properties: {
alwaysLog: 'allErrors'
verbosity: 'verbose'
logClientIp: true
loggerId: apimLogger.id
sampling: {
samplingType: 'fixed'
percentage: 100
}
largeLanguageModel: {
logs: 'enabled'
requests: {
messages: 'all'
maxSizeInBytes: 262144
}
responses: {
messages: 'all'
maxSizeInBytes: 262144
}
}
}
}Bicep Best Practices
Use Existing Resources
resource apim 'Microsoft.ApiManagement/service@2024-06-01-preview' existing = {
name: apimServiceName
}Parameter Validation
@description('The pricing tier')
@allowed(['Consumption', 'Developer', 'Basic', 'Basicv2', 'Standard', 'Standardv2', 'Premium', 'Premiumv2'])
param sku string = 'Basicv2'
@minLength(1)
@maxLength(50)
param apiManagementName stringLoad External Content
// Load JSON for OpenAPI specs
value: string(loadJsonContent('./specs/openapi.json'))
// Load XML for policies
value: loadTextContent('policy.xml')
// Load and parameterize policy
var updatedPolicy = replace(loadTextContent('policy.xml'), '{backend-id}', backendName)Output Secrets Safely
#disable-next-line outputs-should-not-contain-secrets
output subscriptionKey string = subscription.listSecrets().primaryKeyReference Documentation
- Shared modules in this repo:
shared/bicep/modules/apim/v1/(api, apim, backend, backend-pool, diagnostics, named-value, policy-fragment, product)
Official Documentation
Other versions1 project uses a version of this.
Word for word · 0
None found.
Edited · 1
- Azure-Samples/AI-Gateway★ 98869% same
Wrote their own version · 0
None found.
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository4 other files it gives its agents.
- AGENTS.mdAGENTS.md
- .github/copilot-instructions.mdCopilot instructions
- apim-policiesSkill
- sample-creatorSkill
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

