2.1 - AZD Workflow
Welcome to Week 2! This week we deep dive into Azure Developer CLI. Today we explore the complete AZD workflow and understand each commandβs purpose.
What Youβll Learn
Section titled βWhat Youβll Learnβ- The complete AZD workflow from start to finish
- When and why to use each AZD command
- Environment management and configuration
- Best practices for AZD-based development
Resources
Section titled βResourcesβBefore diving in, review these resources:
- π AZD Architecture and Concepts - Understanding AZD internals
- π AZD Environments - Managing environments and configuration
- π AZD Commands Reference - Complete command documentation
The AZD Development Lifecycle
Section titled βThe AZD Development Lifecycleβββββββββββββββββ azd init β Initialize projectββββββββ¬βββββββ βββββββββββββββββ azd auth β Authenticate to Azureββββββββ¬βββββββ βββββββββββββββββ azd provisionβ Create infrastructureββββββββ¬βββββββ βββββββββββββββββ azd deploy β Deploy applicationββββββββ¬βββββββ βββββββββββββββββ azd monitor β Monitor applicationββββββββ¬βββββββ βββββββββββββββββ azd down β Clean up resourcesβββββββββββββββCore Commands Deep Dive
Section titled βCore Commands Deep Diveβ1. azd init - Project Initialization
Section titled β1. azd init - Project InitializationβPurpose: Start a new project or adopt existing code
Usage Scenarios:
A. From Template
azd init --template Azure-Samples/contoso-chat- Clones template repository
- Creates
.azure/directory - Prompts for environment name
B. From Existing Code
cd my-existing-projectazd init- Detects project structure
- Prompts for services to deploy
- Creates
azure.yamlandinfra/folder
C. Empty Project
mkdir my-new-projectcd my-new-projectazd init- Creates basic structure
- Prompts for language and services
What Gets Created:
.azure/ <env-name>/ .env # Environment variables (gitignored) config.json # Environment configuration2. azd auth login - Authentication
Section titled β2. azd auth login - AuthenticationβPurpose: Authenticate with Azure
Methods:
Interactive Login
azd auth loginOpens browser for Azure authentication
Device Code Flow
azd auth login --use-device-codeFor environments without browser
Service Principal
azd auth login --client-id <id> --client-secret <secret> --tenant-id <tenant>For CI/CD pipelines
Check Authentication
azd auth login --check-status3. azd env - Environment Management
Section titled β3. azd env - Environment ManagementβPurpose: Manage deployment environments
List Environments
azd env listCreate Environment
azd env new <env-name>Select Environment
azd env select <env-name>Set Variables
azd env set API_KEY "your-key-value"azd env set ENABLE_MONITORING trueView Configuration
azd env get-valuesReal-World Example:
azd env new devazd env set AZURE_LOCATION eastusazd env set AZURE_OPENAI_SKU S0
azd env new prodazd env set AZURE_LOCATION westusazd env set AZURE_OPENAI_SKU S0azd env set ENABLE_PRIVATE_ENDPOINTS true4. azd provision - Infrastructure Deployment
Section titled β4. azd provision - Infrastructure DeploymentβPurpose: Create and configure Azure resources
Basic Usage
azd provisionPreview Changes
azd provision --previewShows what will be created/modified (like Terraform plan)
What Happens:
- Reads
azure.yamlandinfra/templates - Prompts for required parameters
- Deploys Bicep templates to Azure
- Captures outputs (endpoints, keys)
- Stores values in
.azure/<env>/.env - Runs post-provision hooks
Time: 5-10 minutes (varies by complexity)
Output Example:
Provisioning Azure resources (azd provision)
(β) Done: Resource group: rg-retailai-dev (β) Done: Azure OpenAI: openai-retailai-dev-abc123 (β) Done: AI Search: search-retailai-dev-abc123 (β) Done: Cosmos DB: cosmos-retailai-dev-abc123 (β) Done: Container Apps Environment: cae-retailai-dev
SUCCESS: Your application was provisioned in 8m 32s5. azd deploy - Application Deployment
Section titled β5. azd deploy - Application DeploymentβPurpose: Build and deploy application code
Basic Usage
azd deployDeploy Specific Service
azd deploy apiazd deploy webWhat Happens:
- Builds application code
- Creates container images (if containerized)
- Pushes images to Azure Container Registry
- Deploys to target hosts (Container Apps, Static Web Apps, etc.)
- Applies environment variables
- Runs post-deploy hooks
Time: 3-5 minutes
Output Example:
Deploying services (azd deploy)
(β) Done: Building api (3m 12s) (β) Done: Deploying api to Container App (1m 45s) (β) Done: Building web (2m 5s) (β) Done: Deploying web to Static Web App (1m 8s)
SUCCESS: Your application was deployed in 5m 10s
Endpoints: web: https://retailai-web-abc123.azurestaticapps.net api: https://api-abc123.eastus.azurecontainerapps.io6. azd up - All-in-One
Section titled β6. azd up - All-in-OneβPurpose: Provision + Deploy in one command
azd upPerfect for:
- Initial deployment
- Fresh environment setup
- Demo scenarios
- Onboarding new developers
Equivalent to:
azd provisionazd deploy7. azd monitor - Application Monitoring
Section titled β7. azd monitor - Application MonitoringβPurpose: View application telemetry and logs
Overview Dashboard
azd monitor --overviewOpens Application Insights overview
Live Logs
azd monitor --logsStreams application logs
Query Logs
azd monitor --logs --query "traces | where severityLevel >= 3"8. azd down - Resource Cleanup
Section titled β8. azd down - Resource CleanupβPurpose: Delete all Azure resources
Basic Usage
azd downForce Delete (no confirmation)
azd down --forcePurge (remove soft-deleted resources)
azd down --purgeWhat Gets Deleted:
- Resource group and all resources
- Deployments
- Role assignments
- Local environment files remain (.azure/ folder)
Environment Configuration
Section titled βEnvironment Configurationβ.azure//.env File
Section titled β.azure//.env FileβAZD stores configuration here:
AZURE_SUBSCRIPTION_ID=12345678-1234-1234-1234-123456789012AZURE_LOCATION=eastusAZURE_RESOURCE_GROUP=rg-retailai-dev
AZURE_OPENAI_ENDPOINT=https://openai-retailai-dev.openai.azure.com/AZURE_SEARCH_ENDPOINT=https://search-retailai-dev.search.windows.netAZURE_COSMOS_ENDPOINT=https://cosmos-retailai-dev.documents.azure.com:443/
API_KEY=your-api-keyENABLE_MONITORING=trueLOG_LEVEL=INFOAccessing in Code
Section titled βAccessing in CodeβPython:
import os
openai_endpoint = os.environ["AZURE_OPENAI_ENDPOINT"]api_key = os.environ["API_KEY"]Node.js:
const openaiEndpoint = process.env.AZURE_OPENAI_ENDPOINT;const apiKey = process.env.API_KEY;Best Practices
Section titled βBest Practicesβ1. Environment Strategy
Section titled β1. Environment Strategyβ- dev: Individual developer environments
- test: Shared testing environment
- staging: Pre-production validation
- prod: Production workloads
2. Configuration Management
Section titled β2. Configuration Managementββ Store in .env: Environment-specific values β Use Key Vault: Sensitive secrets β Version Control: azure.yaml and infra/ templates β Never Commit: .azure/ directory contents
3. Development Workflow
Section titled β3. Development Workflowβazd init --template <template-name>azd auth loginazd up
azd deploy
azd provision --preview # Preview changesazd provision # Apply changes
azd down4. Team Collaboration
Section titled β4. Team CollaborationβOption A: Shared Dev Resources
- One dev environment
- Quick but can have conflicts
Option B: Individual Environments
- Each developer has own environment
- Higher cost but isolated
Option C: Ephemeral Environments
- Create, use, destroy
- Best cost/isolation balance
Hooks for Customization
Section titled βHooks for CustomizationβAdd custom logic to workflow:
azure.yaml hooks
Section titled βazure.yaml hooksβhooks: preprovision: - echo "About to provision..."
postprovision: - azd env set API_ENDPOINT $(az containerapp show -g $AZURE_RESOURCE_GROUP -n api --query properties.configuration.ingress.fqdn -o tsv)
predeploy: - npm run test
postdeploy: - echo "Deployment complete!" - azd env get-valuesTroubleshooting Commands
Section titled βTroubleshooting CommandsβCheck AZD Version
azd versionUpdate AZD
azd upgradeView Detailed Logs
azd provision --debugShow Help
azd --helpazd provision --helpAsk Copilot
Section titled βAsk CopilotβExplore AZD workflow:
- βWhatβs the difference between running βazd upβ once versus running βazd provisionβ followed by multiple βazd deployβ commands during development?β
- βHow do you safely manage secrets and API keys when using azd for deployment?β
- βWhat happens to Azure resources if you delete the .azure directory locally?β
Related Resources
Section titled βRelated ResourcesβNext: Day 9 - Installation & Commands
Tomorrow weβll cover AZD installation across platforms and explore all available commands in detail.