Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Prepare applications for Azure deployment by generating infrastructure code, Dockerfiles, and config files.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/recipes/bicep/patterns.md
1# Bicep Patterns23Common patterns for Bicep infrastructure templates.45## File Structure67```8infra/9โโโ main.bicep # Entry point (subscription scope)10โโโ main.parameters.json # Parameter values11โโโ modules/12โโโ resources.bicep # Base resources13โโโ container-app.bicep # Container App module14โโโ ...15```1617## main.bicep Template1819```bicep20targetScope = 'subscription'2122@minLength(1)23@maxLength(64)24param environmentName string2526@minLength(1)27param location string2829var tags = { environment: environmentName }3031resource rg 'Microsoft.Resources/resourceGroups@2023-07-01' = {32name: 'rg-${environmentName}'33location: location34tags: tags35}3637module resources './modules/resources.bicep' = {38name: 'resources'39scope: rg40params: {41location: location42environmentName: environmentName43tags: tags44}45}4647output resourceGroupName string = rg.name48```4950## main.parameters.json5152> โ ๏ธ **Warning:** This file uses ARM JSON syntax. Do **not** use `.bicepparam` syntax (`using`, `param`, `readEnvironmentVariable()`) in this file โ `azd` will fail with a JSON parse error.5354```json55{56"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",57"contentVersion": "1.0.0.0",58"parameters": {59"environmentName": { "value": "${AZURE_ENV_NAME}" },60"location": { "value": "${AZURE_LOCATION}" }61}62}63```6465Use `azd env set` to supply values at deploy time:6667```bash68azd env set AZURE_ENV_NAME myapp-123469azd env set AZURE_LOCATION eastus270```7172## Naming Convention7374```bicep75var resourceToken = uniqueString(subscription().id, resourceGroup().id, location)7677// Pattern: {prefix}{name}{token}78// Total โค32 chars, alphanumeric only79var kvName = 'kv${environmentName}${resourceToken}'80var storName = 'stor${resourceToken}'8182// Container Registry: alphanumeric only (5-50 chars)83var acrName = replace('cr${environmentName}${resourceToken}', '-', '')84```8586## Security Requirements8788| Requirement | Pattern |89|-------------|---------|90| No hardcoded secrets | Use Key Vault references |91| Managed Identity | `identity: { type: 'UserAssigned' }` |92| HTTPS only | `httpsOnly: true` |93| TLS 1.2+ | `minTlsVersion: '1.2'` |94| No public blob access | `allowBlobPublicAccess: false` |9596## Common Modules9798### Log Analytics99100```bicep101resource logAnalytics 'Microsoft.OperationalInsights/workspaces@2022-10-01' = {102name: 'log-${resourceToken}'103location: location104properties: {105sku: { name: 'PerGB2018' }106retentionInDays: 30107}108}109```110111### Application Insights112113```bicep114resource appInsights 'Microsoft.Insights/components@2020-02-02' = {115name: 'appi-${resourceToken}'116location: location117kind: 'web'118properties: {119Application_Type: 'web'120WorkspaceResourceId: logAnalytics.id121}122}123```124125### Key Vault126127```bicep128resource keyVault 'Microsoft.KeyVault/vaults@2023-07-01' = {129name: 'kv-${resourceToken}'130location: location131properties: {132sku: { family: 'A', name: 'standard' }133tenantId: subscription().tenantId134enableRbacAuthorization: true135}136}137```138139