How does the deploy to Azure button work?

I was noticing following button more often lately while looking at official Azure docs or GitHub repositories.

Deploy to Azure

This is backed by a hyperlink and allows you to deploy a given ARM template to your own Azure subscription. Very useful for helping readers out in deploying samples or even a complete solution. So of course I was asking myself the question: “How does this work?” as I wanted to start using it myself.

The good news is that there’s already a nice official page on how to build the URI behind the button.

In short it comes down to:

  • Store your ARM templates in GitHub.
  • URL-encode the RAW URL to the file.
  • Put this URL in front of the encoded one:
  • Put your complete URI behind the fancy button:
[![Deploy to Azure](]({encodedURI})

I’ve put up a small GitHub repository with a JSON ARM template and a Bicep template. This allows me to create following button to deploy an Azure Storage Account.

Deploy to Azure

I’ll certainly start adding these buttons to my own repositories to help visitors out. Using Azure DevOps instead of GitHub? The documentation got you covered as well.

What the article currently fails to mention is what’s behind this magic link. Let’s visit the first part of the URI: You reach the same place when searching for ‘Deploy a custom template’ in the services search bar.

This page is possibly the easiest way to deploy custom ARM templates, without the need for a DevOps pipeline, PowerShell or Azure CLI. There are many ways to get these custom templates:

  • Export the template of previously deployed resources.
  • Use one of the common templates on that page.
  • Start from a quickstart (community) template.
  • Write one completely from scratch.

It also allows you to start editing a template with a visual editor with all the components in your template in the navigation menu.

Custom Deploy Editor

The second part of the link is of course your own template. This allows us to inject the template and start the deployment process. All you have to do is provide parameter values in case you want to override these and you’re set.

What about Bicep templates?

You can build Bicep templates to ARM JSON templates, which gives you a file to deploy. But of course this isn’t the approach you want when having small Bicep template files as samples as it beats the purpose of creating Bicep samples. Trying to above trick with a Bicep file gives you following error in the portal:

Bicep deployment failing

There’s already a GitHub issue open to cover this scenario. And I hope that one day the button below works as well to deploy the Bicep variant of the above template.

Deploy to Azure

Private repositories

Of course you’ll now say: that’s cool, but I don’t want all my ARM templates to be public. Good news, fellow MVP Tao Yang wrote a blog post on how to use an Azure Function to deploy private templates.

Licensed under CC BY-NC-SA 4.0; code samples licensed under MIT.
comments powered by Disqus
Built with Hugo - Based on Theme Stack designed by Jimmy