Course contentsShow
← Cloud and Infrastructure
Lesson 909 of 2,98917. Azure ARM Templates and BicepFree lesson

Deployment Scripts in ARM Templates

Execute custom PowerShell or Bash scripts during template deployment for tasks beyond native ARM capabilities.

Deployment Scripts in ARM Templates

What you'll learn: How to execute custom PowerShell or Bash scripts within ARM template deployments to handle tasks that ARM resources alone cannot accomplish.

The Core Idea

Sometimes ARM templates can't do everything you need natively—like calling external APIs, performing complex data transformations, or configuring resources that require imperative logic. Deployment scripts let you embed PowerShell or Bash scripts directly into your ARM template, and Azure will execute them during deployment using temporary Azure Container Instances.

Think of deployment scripts as a "trapdoor" in your declarative template: when you hit the limits of what ARM's JSON can express, you drop into scripting mode to handle the exceptional case, then climb back out with the results.

How They Work

Deployment scripts are declared as ARM resources with type Microsoft.Resources/deploymentScripts. You specify:

  • Script type: PowerShell or Bash
  • Script content: Inline or from a file URI
  • Managed identity: For Azure authentication
  • Outputs: Variables your script produces that other template resources can reference

Azure spins up a temporary container, runs your script, captures outputs, and cleans up. The script can authenticate to Azure services, call REST APIs, or perform file operations—anything a shell script can do.

Common Use Cases

  • Generating random passwords or keys not available via ARM functions
  • Calling third-party APIs to register resources
  • Performing custom validation or pre-flight checks
  • Initializing databases or storage with seed data
  • Waiting for external systems to be ready

Key Takeaway: Deployment scripts extend ARM templates with imperative scripting capabilities, letting you handle complex deployment logic that pure declarative JSON cannot express—bridging the gap between infrastructure-as-code and custom automation.