Skip to content

Instantly share code, notes, and snippets.

@chgeuer
Last active April 6, 2022 10:27
Show Gist options
  • Save chgeuer/c1e4b03f36e8b98a44ec5b0ce6287345 to your computer and use it in GitHub Desktop.
Save chgeuer/c1e4b03f36e8b98a44ec5b0ce6287345 to your computer and use it in GitHub Desktop.

Set and use results from a deploymentScript in an ARM/bicep template

Set the values in your (bash) script

arm_marketplace_vm_delete_post_deploy/deleteVM.sh at main · chgeuer/arm_marketplace_vm_delete_post_deploy (github.com)

# Create JSON structure
output="$( echo "{}" | \
    jq --arg x "${login_output}" '.tasks.login=($x | fromjson)' | \
    jq --arg x "${vm_output}"    '.tasks.vm=($x | fromjson)'    | \
    jq --arg x "${disk_output}"  '.tasks.disk=($x | fromjson)'  | \
    jq --arg x "${nic_output}"   '.tasks.nic=($x | fromjson)'   | \
    jq --arg x "${ip}"           '.ip=$x'                       )"

# https://docs.microsoft.com/en-us/azure/azure-resource-manager/templates/deployment-script-template?tabs=CLI#work-with-outputs-from-cli-script
echo "${output}" > "${AZ_SCRIPTS_OUTPUT_PATH}"

Refer to deploymentScript outputs

arm_marketplace_vm_delete_post_deploy/mainTemplate.json at main · chgeuer/arm_marketplace_vm_delete_post_deploy (github.com)

 "outputs": {
    "ip": { "value": "[reference(variables('names').deploymentScript).outputs.ip]", "type": "string" },
    "tasks": { "value": "[reference(variables('names').deploymentScript).outputs.tasks]", "type": "object" }
  }
```s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment