Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Prepare Azure environments for new workloads—subscriptions, networking, identity, and landing zones
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/recipes/azd/azure-yaml.md
1# azure.yaml Generation23> ⛔ **CRITICAL: Check for .NET Aspire projects FIRST**4>5> **DO NOT manually create azure.yaml for .NET Aspire projects.** If you detect:6> - Files ending with `*.AppHost.csproj` (e.g., `MyApp.AppHost.csproj`)7> - `Aspire.Hosting` or `Aspire.AppHost.Sdk` in `.csproj` files8>9> **STOP and use `azd init --from-code` instead.** See [aspire.md](aspire.md) for details.1011Create `azure.yaml` in project root for AZD.1213## Structure1415### Basic (Bicep - default)1617```yaml18name: <project-name>19metadata:20template: azd-init2122services:23<service-name>:24project: <path-to-source>25language: <python|js|ts|java|dotnet|go>26host: <containerapp|appservice|function|staticwebapp|aks>27```2829### With Terraform Provider3031```yaml32name: <project-name>33metadata:34template: azd-init3536# Specify Terraform as IaC provider37infra:38provider: terraform39path: ./infra4041services:42<service-name>:43project: <path-to-source>44language: <python|js|ts|java|dotnet|go>45host: <containerapp|appservice|function|staticwebapp|aks>46```4748> 💡 **Tip:** Omit `infra` section to use Bicep (default). Add `infra.provider: terraform` to use Terraform. See [terraform.md](terraform.md) for details.4950## Host Types5152| Host | Azure Service | Use For |53|------|---------------|---------|54| `containerapp` | Container Apps | APIs, microservices, workers |55| `appservice` | App Service | Traditional web apps |56| `function` | Azure Functions | Serverless functions |57| `staticwebapp` | Static Web Apps | SPAs, static sites |58| `aks` | AKS | Kubernetes workloads |5960## Examples6162### Container App with Bicep (default)6364```yaml65name: myapp6667services:68api:69project: ./src/api70language: python71host: containerapp72docker:73path: ./src/api/Dockerfile74```7576### Container App with Terraform7778```yaml79name: myapp8081infra:82provider: terraform83path: ./infra8485services:86api:87project: ./src/api88language: python89host: containerapp90docker:91path: ./src/api/Dockerfile92```9394### Container App with Custom Docker Context9596When a **non-Aspire** project has a Dockerfile that expects files relative to a specific directory:9798```yaml99name: myapp100101services:102ginapp:103project: .104host: containerapp105image: ginapp106docker:107path: ginapp/Dockerfile108context: ginapp109```110111> 💡 **Tip:** The `context` field specifies the Docker build context directory. This is crucial for:112> - Dockerfiles with `COPY` commands expecting files relative to a subdirectory113> - Multi-service repos where each service has its own context114115> ⚠️ **Aspire projects:** Do NOT manually add per-service entries with `docker.context` for Aspire `AddDockerfile()` resources. Aspire handles container builds at runtime through the AppHost. The generated `azure.yaml` should contain only a single `app` service pointing to the AppHost. See [aspire.md](aspire.md) for details.116117> ⚠️ **Language Field:** When using the `docker` section, the `language` field should be **omitted** or set to the language that azd will use for framework-specific behaviors. For containerized apps with custom Dockerfiles, the language is not used by azd since the build is handled by Docker. Only include `language` if you need azd to perform additional framework-specific actions beyond Docker build.118119### Azure Functions120121```yaml122services:123functions:124project: ./src/functions125language: js126host: function127```128129### Static Web App (with framework build)130131For React, Vue, Angular, Next.js, etc. that require `npm run build`:132133```yaml134services:135web:136project: ./src/web # folder containing package.json137language: js # triggers: npm install && npm run build138host: staticwebapp139dist: dist # build output folder (e.g., dist, build, out)140```141142### Static Web App (pure HTML/CSS - no build)143144For pure HTML sites without a framework build step:145146**Static files in subfolder (recommended):**147```yaml148services:149web:150project: ./src/web # folder containing index.html151host: staticwebapp152dist: . # works when project != root153```154155**Static files in root - requires build script:**156157> ⚠️ **SWA CLI Limitation:** When `project: .`, you cannot use `dist: .`. Files must be copied to a separate output folder.158159Add a minimal `package.json` with a build script:160```json161{162"scripts": {163"build": "node -e \"require('fs').mkdirSync('public',{recursive:true});require('fs').readdirSync('.').filter(f=>/\\.(html|css|js|png|jpe?g|gif|svg|ico|json|xml|txt|webmanifest|map)$/i.test(f)).forEach(f=>require('fs').copyFileSync(f,'public/'+f))\""164}165}166```167168Then configure azure.yaml with `language: js` to trigger the build:169```yaml170services:171web:172project: .173language: js # triggers npm install && npm run build174host: staticwebapp175dist: public176```177178### SWA Project Structure Detection179180| Layout | Configuration |181|--------|---------------|182| Static in root | `project: .`, `language: js`, `dist: public` + package.json build script |183| Framework in root | `project: .`, `language: js`, `dist: <output>` |184| Static in subfolder | `project: ./path`, `dist: .` |185| Framework in subfolder | `project: ./path`, `language: js`, `dist: <output>` |186187> **Key rules:**188> - `dist` is **relative to `project`** path189> - **SWA CLI limitation**: When `project: .`, cannot use `dist: .` - must use a distinct folder190> - For static files in root, add `package.json` with build script to copy files to dist folder191> - Use `language: js` to trigger npm build even for pure static sites in root192> - `language: html` and `language: static` are **NOT valid** - will fail193194### SWA Bicep Requirement195196Bicep must include the `azd-service-name` tag:197```bicep198resource staticWebApp 'Microsoft.Web/staticSites@2022-09-01' = {199name: name200location: location201tags: union(tags, { 'azd-service-name': 'web' })}202```203}204```205206### App Service207208```yaml209services:210api:211project: ./src/api212language: dotnet213host: appservice214```215216## Hooks (Optional)217218```yaml219hooks:220preprovision:221shell: sh222run: ./scripts/setup.sh223postprovision:224shell: sh225run: ./scripts/seed-data.sh226```227228## Valid Values229230| Field | Options |231|-------|---------|232| `language` | python, js, ts, java, dotnet, go (omit for staticwebapp without build) |233| `host` | containerapp, appservice, function, staticwebapp, aks |234| `docker.path` | Path to Dockerfile (relative to project root) |235| `docker.context` | Docker build context directory (optional, defaults to directory containing Dockerfile) |236237> 💡 **Docker Context:** When `docker.context` is omitted, azd uses the directory containing the Dockerfile as the build context. Specify `context` explicitly when the Dockerfile expects files from a different directory.238239## Output240241- `./azure.yaml`242