By now if you have done any work with Azure Resource Manager (ARM) JSON templates you have probably seen the “Deploy to Azure” button. The “Deploy to Azure” button looks like this.
If you aren’t familiar with this, have a look at some of the templates in the Azure Quickstart Templates github repo. This is where you will find a lot of sample templates that you can test and/or modify for your own use.
The “Deploy to Azure” button comes in really handy when you want to quickly deploy a template. Although you will find this mostly in github repos you could use this anywhere by simply adding the code. Upon clicking on this button, you will be redirected to the Azure Portal where a blade will open waiting for you to enter the parameters for the deployment. Ok, this is cool so how do I add it? We are getting to that now.
I have seen a few references to the button in other blogs but couldn’t really find out exactly how this is done. With a little testing I figured it out and so I thought I would share with you how you can add this button. I will discuss this from a github repo perspective but as I mentioned above you could utilize this button in other places as well.
What you will want to do is to copy this code block and paste it into your README.md file.
1 2 3 |
<a href="https://portal.azure.com/#create/Microsoft.Template/uri/https%3A%2F%2Fraw.githubusercontent.com%2FDarylsCorner%2FARM-Templates%2Fmaster%2Fvm-from-user-image%2Fazuredeploy.json" target="_blank"> <img src="http://azuredeploy.net/deploybutton.png"/> </a> |
The only part you need to change is the location of your template. This is the portion after …/uri/ and before target=. In your Github repo, click on your azuredeploy.json file and click Raw. Copy the link and go back to your README.md file and paste it in. Now you would think this is all that is needed and everything would just work. Wrong.
So why is that? URLs use some characters for special use in defining their syntax. When these characters are not used in their special role inside a URL, they need to be encoded. Some examples include the colon and forward slash. It just so happens we have both of those in our URL. So how is this done? URL encoding of a character consists of a “%” symbol, followed by the two-digit hexadecimal representation (case-insensitive) of the ISO-Latin code point for the character.
So if you look at the code block above you will see that we are using %3A in place of the colon and %2F in place of each forward slash. Once this is done make sure to commit your changes and viola! You now have a “Deploy to Azure” button that will allow for a streamlined deployment process.
I hope this post has been helpful and you find this useful. Stay tuned for another exciting and interesting button that we will discuss tomorrow called “Visualize”.