Skip to content

jongio/azd-hooks-languages

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

azd Hooks Languages

An Azure Developer CLI template showing how to write hooks in Python, JavaScript, and TypeScript - multi-language hook support added in azd 1.23.15.

Before 1.23.15, hooks were limited to Bash and PowerShell. Now you can point directly at .py, .js, or .ts files and azd handles dependency management automatically.

Prerequisites

Quick start

azd init -t jongio/azd-hooks-languages
azd up

You'll see all three hooks fire during the workflow - Python validates before provisioning, JavaScript generates a report after, and TypeScript runs a health check at the end.

Project structure

azure.yaml                          # Hook config - points to each script
hooks/
  preprovision/
    validate.py                     # Python validation hook
    requirements.txt                # colorama (auto-installed by azd)
  postprovision/
    report.js                       # JavaScript report hook
    package.json                    # chalk (auto-installed by azd)
  postup/
    healthcheck.ts                  # TypeScript health check hook
    package.json                    # chalk, tsx (auto-installed by azd)
infra/
  main.bicep                        # Minimal Bicep - creates a resource group

Hooks

preprovision/validate.py - Pre-provision validation

Runs before azd provision. Validates that:

  • AZURE_ENV_NAME and AZURE_LOCATION are set
  • Environment name is 20 chars or less
  • Environment name uses only letters, numbers, and hyphens
  • Environment name doesn't start or end with a hyphen

Exits with code 1 on failure, which stops provisioning.

postprovision/report.js - Deployment report

Runs after azd provision. Collects environment details (resource group, location, subscription) and writes a JSON report to .azure/reports/deploy-<env-name>.json. Uses path.basename to sanitize the filename.

postup/healthcheck.ts - Health check

Runs after azd up completes. Verifies all required environment values are populated and checks that the resource group actually exists in Azure via az group show. Uses typed interfaces (DeploymentConfig, CheckResult) and execFileSync for safe CLI calls.

How azd manages dependencies

In azure.yaml, each hook just points to the script file with a relative path:

hooks:
  preprovision:
    run: hooks/preprovision/validate.py
  postprovision:
    run: hooks/postprovision/report.js
  postup:
    run: hooks/postup/healthcheck.ts

azd auto-detects the language from the file extension and handles the rest:

  • Python (.py): Creates a virtual environment and runs pip install -r requirements.txt if present
  • JavaScript (.js): Runs npm install from package.json if present
  • TypeScript (.ts): Runs via npx tsx - no compile step needed. Installs package.json dependencies first if present

Known issue in 1.23.15: The run: + dir: syntax doesn't trigger language auto-detection. Use full relative paths (e.g., run: hooks/preprovision/validate.py) instead of dir: hooks/preprovision + run: validate.py.

Before 1.23.15

Previously you had to wrap everything in a shell script:

# The old way - shell wrapper required
hooks:
  preprovision:
    shell: sh
    run: |
      python3 -m venv .venv
      .venv/bin/pip install -r requirements.txt
      .venv/bin/python validate.py

Now it's just:

hooks:
  preprovision:
    run: hooks/preprovision/validate.py

Learn more

License

MIT

About

Azure Developer CLI template demonstrating Python, JavaScript, and TypeScript hooks with auto dependency management. Requires azd 1.23.15+.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors