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/app-service/templates/recipes/composition.md
1# Composition Algorithm — REFERENCE ONLY23Step-by-step algorithm for composing a base App Service template with an integration recipe.45> **This is the authoritative process. Follow it exactly.**67## Algorithm89```10INPUT:11- language: dotnet | typescript | javascript | python | java12- scenario: web-api | web-app13- integration: none | sql | cosmos | auth | redis14- iac: bicep | terraform1516OUTPUT:17- Complete project directory ready for `azd up`18```1920### Step 1: Fetch Base Template2122```bash23# Determine template by scenario + language24IF scenario == 'web-api':25TEMPLATE = web_api_templates[language] # See web-api.md26ELSE IF scenario == 'web-app':27TEMPLATE = web_app_templates[language] # See web-app.md2829# Non-interactive init30ENV_NAME="$(basename "$PWD" | tr '[:upper:]' '[:lower:]' | tr ' _' '-')-dev"31# PowerShell: $ENV_NAME = "$(Split-Path -Leaf (Get-Location) | ForEach-Object { $_.ToLower() -replace '[ _]','-' })-dev"32azd init -t $TEMPLATE -e "$ENV_NAME" --no-prompt33```3435### Step 2: Check if Recipe Needed3637```38IF integration IN [none]:39→ DONE. Base template is complete.4041IF integration IN [sql, cosmos, redis, auth]:42→ Full recipe. Continue to Step 3.43```4445### Step 3: Add IaC Module (for full recipes only)4647**Bicep:**481. Read recipe's `README.md` for the Bicep module file492. Copy module into `infra/app/`503. Add module reference in `infra/main.bicep`:51```bicep52module sqlServer './app/sql.bicep' = {53name: 'sqlServer'54scope: rg55params: {56name: name57location: location58tags: tags59appServicePrincipalId: web.outputs.SERVICE_WEB_IDENTITY_PRINCIPAL_ID60}61}62```634. If VNET_ENABLED, add the network module for private endpoints6465**Terraform:**661. Copy recipe `.tf` files into `infra/`672. Merge app settings into web app resource block683. Networking uses `count = var.vnet_enabled ? 1 : 0`6970### Step 4: Add App Settings7172Read the recipe's `README.md` for required app settings. Add them to the web app config.7374> **CRITICAL: Managed Identity Configuration**75>76> For service bindings, prefer User Assigned Managed Identity (UAMI).77> Always include connection settings that reference managed identity, not passwords:78>79> ⚠️ **Connection-string format is language-specific.** The example below is **.NET / ADO.NET** format. For other stacks, use the per-language env vars documented in `recipes/sql/source/{language}.md`:80>81> | Language | Env var(s) | Format |82> |---|---|---|83> | .NET | `AZURE_SQL_CONNECTION_STRING` | `Server=...;Authentication=Active Directory Managed Identity;User Id=<clientId>;` (ADO.NET) |84> | Python | `AZURE_SQL_SERVER`, `AZURE_SQL_DATABASE`, `AZURE_CLIENT_ID` | Code obtains MI access token and passes via ODBC `attrs_before` |85> | Node.js | `DATABASE_URL` | `sqlserver://<host>:1433;database=<db>;authentication=ActiveDirectoryMsi;clientId=<clientId>` (Prisma) |8687> ```bicep88> appSettings: [89> { name: 'AZURE_SQL_CONNECTION_STRING', value: 'Server=${sqlServer.properties.fullyQualifiedDomainName};Database=${dbName};Authentication=Active Directory Managed Identity;User Id=${managedIdentity.properties.clientId};' }90> ]91> ```9293### Step 5: Add Source Code Integration94951. Read `recipes/{integration}/source/{language}.md`962. Add the integration code (service client, middleware, configuration)973. Add package dependencies (NuGet, npm, pip, Maven)9899> ⛔ **Do NOT replace the main entry point file** (Program.cs, app.py, index.js).100> Recipes ADD integration code alongside the existing application code.101102### Step 6: Update azure.yaml (if needed)103104Some recipes require hooks:105```yaml106hooks:107postprovision:108posix:109shell: sh110run: ./infra/scripts/setup-db.sh111windows:112shell: pwsh113run: ./infra/scripts/setup-db.ps1114```115116### Step 7: Validate and Deploy117118**Required Environment Setup:**119```bash120azd env set AZURE_LOCATION eastus2121```122123**Deployment (two-phase recommended):**124```bash125azd provision --no-prompt # Create resources + RBAC assignments126sleep 60 # Wait for RBAC propagation127azd deploy --no-prompt # Deploy code (RBAC now active)128```129130> **CRITICAL: Never store database passwords in app settings.**131> The correct approach is managed identity with passwordless connections.132133## Critical Rules1341351. **NEVER synthesize Bicep or Terraform from scratch** — always start from base template IaC1362. **Do not restructure or replace base IaC files** — only ADD recipe modules alongside them1373. **ALWAYS use recipe RBAC role GUIDs** — never let the LLM guess role IDs1384. **ALWAYS use `--no-prompt`** — the agent must never elicit user input during azd commands1395. **ALWAYS include a health check endpoint** at `/health`1406. **ALWAYS use managed identity** — no connection strings with passwords1417. **ALWAYS tag the App Service** with `azd-service-name` matching `azure.yaml`142