This is continuation azure series. Although, I have started the series on my medium blog https://medium.com/@rahulsahay19, I am moving the same here in my word-press blog as I find managing and grouping is much easier here than on medium. Earlier posts, you can view medium itself. Also, new posts will also available as part of cross posts. But, this will be primary blog.
In this section, we will be discussing automation for the deployment of virtual machines. Within MS Azure, automation is usually done using ARM template aka Azure Resource Manager model which is the modern way of deploying resources into azure. The opposite of ARM is ASM aka classic deployment model, which we don’t use any more.
Let’s start this process for the deployment of Virtual Machine. Normally, whenever we deploy any VM, its deployment page appear like this
- On the left hand side, you can see you have template section.
- When we click on this, it will present the below UI. It consists two files: 1) Templates and 2) Parameter file.
- Earlier it used to be CLI, Powershell, .Net, Ruby scripts also. But now only scripts section which look like
- Now, I can go ahead and download the template from the download button.
- In the downloaded template, I got parameters and template like
- Parameters JSON file looks like this.
- And template goes like
templates.json file starts with schema as appeared at the top of the file. Then, it also has various parameters in it. This we will eventually use to modify the same.
- Variables are similar to parameters; only thing is that these are computed fields.
- Key section here is the resources section. This is where all the resources are within this deployment gets defined.
- Last section is the output. This ARM template is going to return admin user name as its output.
- In case, of parameters, there is going to be one parameter for each of the parameter defined by the template.
- The template has one location parameter which is string and in the parameters file, the location is being sent to EastUS.
- The way these got these values, how we initially created VM from UI. So, it has grabbed all the values as part of template.
Now, let’s take an example of Network Interface card and explain the same in detail.
- It starts with type Microsoft.Network/networkInterfaces. So, this is the network interface resource.
- It takes the name of the card from the parameters section.
- It has some pretty static code for API version.
- The location is the same as we pass in the parameters.
- Similarly, we have applied tags.
- Network interface card has this IP address which is being setup in the next property under ipconfig.
- Down, its giving network security group and nsgId.
And the last thing which I wanted to discuss here is the dependency. It depends on
Hence, above listed dependencies need to be created first. Here is the list dependencies
Creating a VM with ARM template
- Creating a VM with ARM template is complex task.
- In that case, network interface card, its dependencies and then others has to be created first.
- So, let’s start with bare minimum changes to start with. Therefore, I will start with network interface card.
- I will give it a new name say “rahulnic123″
- I am going to keep the same network security group and we will launch in the same virtual network.
- However, its going to need the new public ip address, hence say it “azvmdemo2-ip”.
- Change the name of VM to “azvmdemo2″.
- Leave the other settings as same. So currently, I have modified the parameters file.
- Here, azure will consider this template as baseline template as we haven’t changed anything in template and then it can deploy the same template again and again with changed parameters value. This is known as Desired state configuration aka DSC.
- Hence, we can take these files, have it in our source control and then we can just do versioning on top of it.
- This is also known as Infrastructure as a service.
- Click on Add or Create Template
- Enter details like
- Click OK and then select the ARM template
- Now, drop your ARM template from the machine and click ok
- Now, click on Add button as shown above. This will drop a template file like shown below
- Now, I can go ahead and click on deploy like shown below.
- So, this will present me below UI. Here, I can choose to enter all details manually or upload the parameters file which we modified already.
- Now, click on save.
- Here, you can see almost all the parameters uploaded. RG and password, you need to fill in and then click on purchase.
- Here, you can see; validation is going on. And then off-course the deployments page as usual like shown below
- Finally, deployment is complete.
One thing to note here that ARM templates is almost for any resource. Its not limited to VM only.
- Its very important, if you are not using the resources. Then delete it to avoid any kind of costing on the resources. I usually, prefer to do it from Resource group directly like shown below.
335 total views, 2 views today