Create an object in Microsoft Azure is very easy and in few minutes it’s possible generate a new virtual machine, or a storage account, ready to be used. If we want create the same object many times, there’s a big chance to have two problems: repeat the same task (boring) and the risk to commit errors.
To avoid this, it’s possible use a cool tool available into the web portal, called Templates.
Azure Resource Manager base the object creation from .json file, completely customizable online or offline that can be imported into the portal to execute simple or advanced tasks very faster. Virtual Machine creation use the same logic and this article we will see how to create a template to create this object; to create a model, there are two ways: from zero and following guide on docs.com or from the wizard portal – this will be my example.
First of all, create a new virtual machine with all the right parameters, like model plan, virtual network, network security group and more.
Figure 1 – New VM
Into the summary view, click on Download template and parameters – figure 2.
Figure 2 – VM Validation
Download the template on your computer, figure 3, that will be in .zip format.
Figure 3 – Download Template
After the download, proceed with the import into the library and give it a right name. This activity will help us to have already a template into the main repository to modify.
From the search bar, on top for Azure Portal, type template and run the service Templates (preview) – figure 4.
Figure 4 – Template Search
Here you can find all the templates that you had saved: virtual machine, storage account, webapp and much more. To show you why we do this, try to click on Deploy button; as you can see that template is with all main information without the values and this means compile the form every time – figure 5.
Figure 5 – Template without Values
Your goal is run the deploy with the most important values already filled, to optimize the time but also to avoid manual errors. Click on button Edit and go to ARM Template – figure 6.
Figure 6 – Editing Template
The template will be modified with the new value from the file parameters located into zip file, downloaded before. Copy the field in each single area that you want fix but be careful at:
- Use the comma after the type (es. Type:string)
- Use the label defaultValue (with the uppercase V) to set the predefined value
Figure 7 – Finalize Template
The final result should be similar like figure 7 (but with your data). Is up to you decide what kind of values automate and what not, for example I suggest to insert the local admin password every time while other values, like VM name, can be compiled. This depends also if you create the template per scope or not.
When you finish, save the configuration and click on button Deploy, to test if everything works fine. The result should be similar like figure 8.
Figure 8 – Template Precompiled
Finalize the form with the rest of information et voilà! If the template is good, after few minutes you will see your virtual machine into the list, ready to be used – figure 9.
Figure 9 – VM Ready
Learn how to use the templates can help admins to automate processing to create object in Azure, much faster than manual mode. Another great value is the possibility to create a central repository, to share them with other colleagues. Thanks to the possibility to pre-compile the fields, the templates reduces the risk to make errors.