1.7 - AZD Templates Introduction
Today we complete the provisioning journey by exploring Azure Developer CLI (AZD) templatesβthe most complete approach to deploying AI applications on Azure.
What Youβll Learn
Section titled βWhat Youβll Learnβ- What Azure Developer CLI (AZD) is and how it differs from ARM/Bicep
- The structure and components of an AZD template
- How AZD templates provide a complete solution (infrastructure + application)
- The
azdworkflow from init to deploy
Resources
Section titled βResourcesβBefore diving in, review these resources:
- π Azure Developer CLI Overview - Official AZD documentation
- π AZD Template Gallery - Curated collection of AZD templates
- π AZD GitHub Repository - Source code and examples
The Apartment Analogy: Full-Service Move-In
Section titled βThe Apartment Analogy: Full-Service Move-InβWeβve progressed through three scenarios:
| Day | Analogy | Approach | Completeness |
|---|---|---|---|
| Day 5 | Buy one chair | Manual provisioning | One resource |
| Day 6 | Buy full kitchen | ARM/Bicep template | Infrastructure |
| Day 7 | Hire move-in coordinator | AZD template | Complete solution |
The AZD Advantage
Section titled βThe AZD AdvantageβHiring a move-in coordinator who:
- Orders and assembles ALL furniture
- Stocks the kitchen with essentials
- Sets up utilities and internet
- Configures smart home devices
- Hangs pictures on walls
- Leaves you with a ready-to-live-in space
You can still customize afterwards, but you start from a fully functional apartment, not an empty one!
What is Azure Developer CLI?
Section titled βWhat is Azure Developer CLI?βAzure Developer CLI (azd) is a command-line tool that:
- Provisions Azure infrastructure
- Deploys application code
- Configures services and connections
- Sets up monitoring and logging
- Provides local development workflow
- Enables CI/CD integration
Key Insight: AZD templates are complete solutions, not just infrastructure definitions.
AZD vs. Other Approaches
Section titled βAZD vs. Other Approachesβ| Feature | Manual | ARM/Bicep | AZD Template |
|---|---|---|---|
| Infrastructure | β | β | β |
| App Code | β | β | β |
| Configuration | β | β | β |
| Local Dev | β | β | β |
| One Command | β | β | β |
| Best Practices | β | β οΈ | β |
| Time to Deploy | Hours | 15-30 min | 5-10 min |
AZD Template Structure
Section titled βAZD Template StructureβAn AZD template is a Git repository with this structure:
my-azd-template/βββ azure.yaml # AZD configurationβββ infra/ # Infrastructure as Codeβ βββ main.bicep # Main infrastructure templateβ βββ main.parameters.jsonβ βββ modules/ # Reusable Bicep modulesβ βββ openai.bicepβ βββ search.bicepβ βββ app-service.bicepβββ src/ # Application source codeβ βββ api/ # Backend APIβ β βββ app.pyβ β βββ requirements.txtβ β βββ Dockerfileβ βββ web/ # Frontend applicationβ βββ package.jsonβ βββ src/βββ .azure/ # AZD environment data (gitignored)βββ .devcontainer/ # Dev container configurationβββ .github/ # GitHub Actions workflowsβ βββ workflows/β βββ azure-dev.ymlβββ README.md # Getting started guideKey Files
Section titled βKey Filesβ1. azure.yaml - The Heart of AZD
Section titled β1. azure.yaml - The Heart of AZDβDefines the template structure and deployment targets:
name: retail-ai-assistantmetadata: template: retail-ai-assistant@0.0.1
services: api: project: ./src/api language: python host: containerapp
web: project: ./src/web language: typescript host: staticwebapp
hooks: postprovision: - azd env set AZURE_OPENAI_ENDPOINT $(az cognitiveservices account show -g ${AZURE_RESOURCE_GROUP} -n ${AZURE_OPENAI_NAME} --query properties.endpoint -o tsv)What it defines:
- Template name and metadata
- Application services (API, web, etc.)
- Which host each service uses (Container Apps, Static Web Apps, etc.)
- Deployment hooks for configuration
2. infra/ - Infrastructure Templates
Section titled β2. infra/ - Infrastructure TemplatesβContains Bicep files defining Azure resources:
targetScope = 'subscription'
@minLength(1)@maxLength(64)@description('Name of the environment')param environmentName string
@minLength(1)@description('Primary location for all resources')param location string
// Create resource groupresource rg 'Microsoft.Resources/resourceGroups@2021-04-01' = { name: 'rg-${environmentName}' location: location}
// Deploy core servicesmodule openai 'modules/openai.bicep' = { scope: rg name: 'openai' params: { name: 'openai-${environmentName}' location: location }}
module containerApps 'modules/container-apps.bicep' = { scope: rg name: 'container-apps' params: { name: 'ca-${environmentName}' location: location }}3. src/ - Application Code
Section titled β3. src/ - Application CodeβYour actual application code:
from flask import Flask, request, jsonifyfrom azure.identity import DefaultAzureCredentialfrom azure.ai.openai import OpenAIClientimport os
app = Flask(__name__)
openai_endpoint = os.environ["AZURE_OPENAI_ENDPOINT"]client = OpenAIClient(openai_endpoint, DefaultAzureCredential())
@app.route("/api/chat", methods=["POST"])def chat(): message = request.json["message"] # Use OpenAI to generate response response = client.chat.completions.create( model="gpt-4", messages=[{"role": "user", "content": message}] ) return jsonify({"response": response.choices[0].message.content})The AZD Workflow
Section titled βThe AZD Workflowβ1. Initialize (azd init)
Section titled β1. Initialize (azd init)βStart from a template:
azd init --template Azure-Samples/contoso-chat
azd initWhat it does:
- Clones template repository (if using existing)
- Creates
.azure/directory for environment data - Prompts for environment name
2. Provision (azd provision)
Section titled β2. Provision (azd provision)βCreate Azure infrastructure:
azd provisionWhat it does:
- Prompts for Azure subscription and region
- Deploys Bicep templates from
infra/ - Creates all Azure resources
- Captures outputs (endpoints, IDs, keys)
- Stores configuration in
.azure/<env>/.env
Time: 5-10 minutes
3. Deploy (azd deploy)
Section titled β3. Deploy (azd deploy)βDeploy application code:
azd deployWhat it does:
- Builds application code
- Creates container images (if needed)
- Deploys to target services (Container Apps, Static Web Apps, etc.)
- Configures environment variables
- Runs any post-deploy hooks
Time: 3-5 minutes
4. All-in-One (azd up)
Section titled β4. All-in-One (azd up)βProvision + Deploy in one command:
azd upThis is the magic command! From zero to deployed application in ~10 minutes.
5. Monitor (azd monitor)
Section titled β5. Monitor (azd monitor)βView application metrics and logs:
azd monitor --overviewazd monitor --logsOpens Application Insights dashboards.
6. Cleanup (azd down)
Section titled β6. Cleanup (azd down)βRemove all resources:
azd downDeletes the resource group and all deployed resources.
AZD Template Benefits
Section titled βAZD Template BenefitsβFor Developers
Section titled βFor Developersββ Fast Start: Working application in minutes β Best Practices: Security, monitoring built-in β Local Development: Dev containers and local testing β Familiar Tools: Use your preferred IDE and languages
For Teams
Section titled βFor Teamsββ Consistency: Everyone uses same setup β Onboarding: New team members productive immediately β Collaboration: Infrastructure as code, code reviewed β Documentation: Template itself is documentation
For Enterprises
Section titled βFor Enterprisesββ Governance: Approved patterns and configurations β Compliance: Security and compliance built-in β Cost Control: Right-sized resources β Auditability: Full deployment history in Git
AZD Template Gallery
Section titled βAZD Template GalleryβMicrosoft and community maintain templates for common scenarios:
AI & ML:
- ChatGPT + Enterprise data (RAG)
- Azure OpenAI + Cosmos DB
- AI Agents with function calling
- Document intelligence processing
Web Applications:
- React + Node.js + PostgreSQL
- .NET Blazor + Azure SQL
- Python Django + Redis
- Next.js + Cosmos DB
APIs & Microservices:
- FastAPI on Container Apps
- .NET minimal APIs
- Dapr microservices
- Event-driven architectures
Explore: azure.github.io/awesome-azd
Week 1 Recap
Section titled βWeek 1 RecapβOver the past week, youβve learned:
β Day 1: Microsoft Foundry platform β Day 2: Enterprise retail AI scenario β Day 3: App development lifecycle (apartment analogy) β Day 4: AI application architecture patterns β Day 5: Manual provisioning (one chair) β Day 6: ARM/Bicep templates (full kitchen) β Day 7: AZD templates (move-in coordinator)
Key Takeaway: AZD templates provide the most complete, efficient way to deploy AI applications on Azure.
Next Week Preview
Section titled βNext Week PreviewβWeek 2: AZD Deep Dive - Weβll explore:
- Installing and configuring AZD
- Finding the right template
- Creating custom templates
- Deploying and customizing
- Deconstructing template structure
- Extending with hooks and plugins
Ask Copilot
Section titled βAsk CopilotβSolidify your understanding:
- βWhat are the key differences between deploying with βazd upβ versus manually running βazd provisionβ and βazd deployβ separately?β
- βHow do AZD templates handle environment-specific configuration for development, staging, and production?β
- βWhat happens under the hood when you run βazd deployβ for a containerized application?β
Related Resources
Section titled βRelated Resourcesβ- AZD CLI Reference
- Creating Your First AZD Template
- AZD Template Best Practices
- AZD Community Discord
Next: Day 8 - AZD Workflow
Congratulations on completing Week 1! Next week we dive deep into mastering Azure Developer CLI.