This post will show you how to use the Azure portal to save JSON templates from an existing resource group.
It is possible to manually deploy a service into a resource group and then create a JSON template from the contents of the resource group; you can use this template as the basis for a new service, or you can create more instances of this service; for example, development, testing, production, and diagnostics.
The process for getting the JSON is very simple. Browse to the resource group in the Azure Portal and select Automation Script.
Note: The Azure Portal is constantly changing, so the names of entries in the GUI might (I should say “will”) change after we publish this article.
The JSON that will duplicate the contents of the resource group is displayed here. You can also see the Parameters JSON file, as well as the CLI, PowerShell, .NET and Ruby options for deploying the JSON template.
There are some interesting actions that you can perform from here:
Let’s save the JSON template in Azure so that we can re-use it. Click Add To Library. You are asked to name the template and add a description.
Tip: You will edit your templates over time. It’s a good idea to version your templates so that you can keep older versions and rollback if necessary.
Any templates that you save in the Azure Portal are associated with your identity and, by default, can only be seen and used by you. Browse to Templates in the Azure Portal; here is where you will see any JSON templates that you have saved or uploaded.
Click the JSON that was just saved. The template is displayed. There are a few actions that you can do:
If you want a quick and dirty re-deployment, then the previous steps can be used to save a template and then you can deploy it without editing it. You’ll find that the template will require a lot of data to be entered as confusingly named parameters, and some items, such as load balancers (NAT and load balancing rules), could be quite complicated to deal with. The editor in the Azure Portal is OK for small tweaks, but it isn’t a great way to make larger changes. The best approach to creating a template that you want to keep is to download the original template and edit it using the free VS Code or Visual Studio.
Browse to the resource group and click the Download action. A zip file will be downloaded by your browser. You will find the following if you extract the contents of the zip file:
You can edit the Template.JSON to make changes to your deployment; typically, I will:
Make sure that your Parameters.JSON is updated to match the Parameters section of the new version of Template.JSON. Then you can deploy the new version of your JSON using: