Skip to content

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.

  • 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

Before diving in, review these resources:

  1. πŸ“˜ AZD Architecture and Concepts - Understanding AZD internals
  2. πŸ“˜ AZD Environments - Managing environments and configuration
  3. πŸ“˜ AZD Commands Reference - Complete command documentation
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ 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
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Purpose: Start a new project or adopt existing code

Usage Scenarios:

A. From Template

Terminal window
azd init --template Azure-Samples/contoso-chat
  • Clones template repository
  • Creates .azure/ directory
  • Prompts for environment name

B. From Existing Code

Terminal window
cd my-existing-project
azd init
  • Detects project structure
  • Prompts for services to deploy
  • Creates azure.yaml and infra/ folder

C. Empty Project

Terminal window
mkdir my-new-project
cd my-new-project
azd init
  • Creates basic structure
  • Prompts for language and services

What Gets Created:

.azure/
<env-name>/
.env # Environment variables (gitignored)
config.json # Environment configuration

Purpose: Authenticate with Azure

Methods:

Interactive Login

Terminal window
azd auth login

Opens browser for Azure authentication

Device Code Flow

Terminal window
azd auth login --use-device-code

For environments without browser

Service Principal

Terminal window
azd auth login --client-id <id> --client-secret <secret> --tenant-id <tenant>

For CI/CD pipelines

Check Authentication

Terminal window
azd auth login --check-status

Purpose: Manage deployment environments

List Environments

Terminal window
azd env list

Create Environment

Terminal window
azd env new <env-name>

Select Environment

Terminal window
azd env select <env-name>

Set Variables

Terminal window
azd env set API_KEY "your-key-value"
azd env set ENABLE_MONITORING true

View Configuration

Terminal window
azd env get-values

Real-World Example:

Terminal window
azd env new dev
azd env set AZURE_LOCATION eastus
azd env set AZURE_OPENAI_SKU S0
azd env new prod
azd env set AZURE_LOCATION westus
azd env set AZURE_OPENAI_SKU S0
azd env set ENABLE_PRIVATE_ENDPOINTS true

Purpose: Create and configure Azure resources

Basic Usage

Terminal window
azd provision

Preview Changes

Terminal window
azd provision --preview

Shows what will be created/modified (like Terraform plan)

What Happens:

  1. Reads azure.yaml and infra/ templates
  2. Prompts for required parameters
  3. Deploys Bicep templates to Azure
  4. Captures outputs (endpoints, keys)
  5. Stores values in .azure/<env>/.env
  6. 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 32s

Purpose: Build and deploy application code

Basic Usage

Terminal window
azd deploy

Deploy Specific Service

Terminal window
azd deploy api
azd deploy web

What Happens:

  1. Builds application code
  2. Creates container images (if containerized)
  3. Pushes images to Azure Container Registry
  4. Deploys to target hosts (Container Apps, Static Web Apps, etc.)
  5. Applies environment variables
  6. 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.io

Purpose: Provision + Deploy in one command

Terminal window
azd up

Perfect for:

  • Initial deployment
  • Fresh environment setup
  • Demo scenarios
  • Onboarding new developers

Equivalent to:

Terminal window
azd provision
azd deploy

Purpose: View application telemetry and logs

Overview Dashboard

Terminal window
azd monitor --overview

Opens Application Insights overview

Live Logs

Terminal window
azd monitor --logs

Streams application logs

Query Logs

Terminal window
azd monitor --logs --query "traces | where severityLevel >= 3"

Purpose: Delete all Azure resources

Basic Usage

Terminal window
azd down

Force Delete (no confirmation)

Terminal window
azd down --force

Purge (remove soft-deleted resources)

Terminal window
azd down --purge

What Gets Deleted:

  • Resource group and all resources
  • Deployments
  • Role assignments
  • Local environment files remain (.azure/ folder)

AZD stores configuration here:

Terminal window
AZURE_SUBSCRIPTION_ID=12345678-1234-1234-1234-123456789012
AZURE_LOCATION=eastus
AZURE_RESOURCE_GROUP=rg-retailai-dev
AZURE_OPENAI_ENDPOINT=https://openai-retailai-dev.openai.azure.com/
AZURE_SEARCH_ENDPOINT=https://search-retailai-dev.search.windows.net
AZURE_COSMOS_ENDPOINT=https://cosmos-retailai-dev.documents.azure.com:443/
API_KEY=your-api-key
ENABLE_MONITORING=true
LOG_LEVEL=INFO

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;
  • dev: Individual developer environments
  • test: Shared testing environment
  • staging: Pre-production validation
  • prod: Production workloads

βœ… Store in .env: Environment-specific values βœ… Use Key Vault: Sensitive secrets βœ… Version Control: azure.yaml and infra/ templates ❌ Never Commit: .azure/ directory contents

Terminal window
azd init --template <template-name>
azd auth login
azd up
azd deploy
azd provision --preview # Preview changes
azd provision # Apply changes
azd down

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

Add custom logic to workflow:

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-values

Check AZD Version

Terminal window
azd version

Update AZD

Terminal window
azd upgrade

View Detailed Logs

Terminal window
azd provision --debug

Show Help

Terminal window
azd --help
azd provision --help

Explore AZD workflow:

  1. β€œWhat’s the difference between running β€˜azd up’ once versus running β€˜azd provision’ followed by multiple β€˜azd deploy’ commands during development?”
  2. β€œHow do you safely manage secrets and API keys when using azd for deployment?”
  3. β€œWhat happens to Azure resources if you delete the .azure directory locally?”

Next: Day 9 - Installation & Commands

Tomorrow we’ll cover AZD installation across platforms and explore all available commands in detail.