Deployment Script


The Deployment Script builder is used to execute Azure CLI scripts as part of an ARM deployment.

  • Deployment Script (Microsoft.Resources/deploymentScripts)

Builder Keywords

nameSets the name of the deployment script resource.
argumentsList of arguments to pass to the script.
cleanup_on_successThe script will only be cleaned up on success to allow for inspection of failures.
cliSpecifies the CLI runtime, default is az cli.
contentSets script content for the resource.
env_varsDefines environment variables in the script environment.
force_update_tagA tag that cn be changed to force a resource update so the script is run again.
identitySets the user assigned identity for the deployment script resource (must be a contributor in the resource group).
primary_script_uriSets a URI to download script content.
retention_intervalSets the hours to retain the script runtime infrastructure to run again quickly.
script_contentSets script content for the resource.
supporting_script_urisSets a URI to download additional content for the script.
timeoutSets the maximum amount of time to allow the script to run.
depends_onSpecifies the resource or resource ID of resources that must exist before script execution.
add_tagsAdds tags to the script runtime resource.
add_tagAdds a tag to the script runtime resource.


open Farmer
open Farmer.Builders

/// The deployment script must run under an identity with any necessary permissions
/// to perform the commands in the script. Also must be a contributor in the
/// resource group.
let scriptIdentity = userAssignedIdentity {
    name "script-user"

/// The script identity must be a contributor over this resource group.
let scriptRole =

/// Define the parameters, identity, and content for the script
let getDateScript = deploymentScript {
    name "custom-script"
    identity scriptIdentity
    force_update_tag (System.DateTime.Now.ToString("o"))
    /// Format output as JSON and pipe to $AZ_SCRIPTS_OUTPUT_PATH to make it available as an output variable.
    content """printf "{'date':'%s'"} "`date`" > $AZ_SCRIPTS_OUTPUT_PATH """

/// The deployment runs the script and gets any output variables.
let template = arm {
    location Location.EastUS
    add_resource scriptIdentity
    add_resource scriptRole
    add_resource getDateScript
    output "date" "[reference('custom-script')]"

Example with dependent resource

let storage = storageAccount {
    name "storagewithstuff"
    add_public_container "public"
/// The deployment script can run azure CLI commands against resources in the
/// same deployment by using 'run_after' and referencing those resources.
let script = deploymentScript {
    name "write-files"
    script_content "echo 'hello world' > hello && az storage blob upload --account-name storagewithstuff -f hello -c public -n hello"
    run_after (ResourceId.create (storageAccounts, storage.Name.ResourceName))
let template = arm {
    location Location.EastUS
    add_resource storage
    add_resource script