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/services/key-vault/bicep.md
1# Key Vault - Bicep Patterns23## Basic Vault45```bicep6resource keyVault 'Microsoft.KeyVault/vaults@2023-07-01' = {7name: '${resourcePrefix}-kv-${uniqueHash}'8location: location9properties: {10tenantId: subscription().tenantId11sku: {12family: 'A'13name: 'standard'14}15enableRbacAuthorization: true16enableSoftDelete: true17softDeleteRetentionInDays: 9018enablePurgeProtection: true19}20}21```2223## Storing Secrets2425```bicep26resource secret 'Microsoft.KeyVault/vaults/secrets@2023-07-01' = {27parent: keyVault28name: 'database-connection-string'29properties: {30value: databaseConnectionString31}32}33```3435## Role Assignment (Managed Identity)3637```bicep38resource keyVaultRoleAssignment 'Microsoft.Authorization/roleAssignments@2022-04-01' = {39name: guid(keyVault.id, principalId, 'Key Vault Secrets User')40scope: keyVault41properties: {42roleDefinitionId: subscriptionResourceId('Microsoft.Authorization/roleDefinitions', '4633458b-17de-408a-b874-0445c86b69e6')43principalId: principalId44principalType: 'ServicePrincipal'45}46}47```4849## Referencing in App Service / Functions5051```bicep52appSettings: [53{54name: 'DATABASE_URL'55value: '@Microsoft.KeyVault(VaultName=${keyVault.name};SecretName=database-connection-string)'56}57]58```5960## Referencing in Container Apps6162```bicep63secrets: [64{65name: 'db-connection'66keyVaultUrl: '${keyVault.properties.vaultUri}secrets/database-connection-string'67identity: containerApp.identity.principalId68}69]70```7172## Secret with Expiration7374```bicep75resource secret 'Microsoft.KeyVault/vaults/secrets@2023-07-01' = {76parent: keyVault77name: 'api-key'78properties: {79value: apiKey80attributes: {81exp: dateTimeToEpoch(dateTimeAdd(utcNow(), 'P90D'))82}83}84}85```86