Azure, Technology

14. Windows and Linux VMs

Contents

Modify Existing ARM Templates

What are ARM Templates? https://docs.microsoft.com/en-us/azure/azure-resource-manager/templates/overview

ARM Templates allow for the automation of Virtual Machines-

“To implement infrastructure as code for your Azure solutions, use Azure Resource Manager templates (ARM templates). The template is a JavaScript Object Notation (JSON) file that defines the infrastructure and configuration for your project. The template uses declarative syntax, which lets you state what you intend to deploy without having to write the sequence of programming commands to create it. In the template, you specify the resources to deploy and the properties for those resources.”

Template

After you deploy a VM, you can get the template used to create that resource. You can find this in the “Deployments” section.

When you download the template you get 2 JSON files:

  • Template: this is where all of the resources within the deployment get defined. EG: resource group, network adapter, virtual network etc…
    The area you will work in most in the template is the “Resources” section.
    There are dependencies within this section. EG: before the network adapter is create the virtual network and NSG must be defined.
  • Parameters:  this is where the parameters for the deployment are set. EG: location, resource group name, subnet prefix etc…

Editing Template/Parameters

Let’s say you wanted to create a new VM using a template from a VM you already created. You would have to change a couple of items in the Parameters JSON file for this to work. These would be:

  • VM name
  • Network adapter name
  • PublicIP

Other parameters can stay the same, such as:

  • Location
  • Virtual Network
  • Resource Group

DSC (Desired State Configurations)

An example of use for the templates in in DSC.

If you have a Virtual Network configured the way you want it with lots of settings, and want to ensure it keeps these settings, you can use a template with these settings and deploy it every hour. If everything the current Virtual network is the same as in the template, nothing will be changed. But if there are have been changes made to the Virtual Network, the deployment of the template on the hour will revert the settings back to what is in the template.

Deploying a Template

When you go to create a new Resource you get the option to use a template.

1. Azure Portal

  • Go to Templates and you can add your configured template.
  • Then click on “Edit Parameters” and past in your own parameters.
  • You can deploy the template from here.

2. Powershell

You can deploy this using powershell with the Command: New-AzResourceGroupDeployment

https://docs.microsoft.com/en-us/powershell/module/az.resources/new-azresourcegroupdeployment?view=azps-5.9.0

 

ARM Custom Script Extensions

This allow you to deploy software and make other changes post deployment.

You can add paths to scripts in the ARM template so they run once the VM has been deployed.

 

ARM Using VHD

Another method of deploying a VM with preconfigured software is to use a VHD. You can have a drive already setup with the necessary software and configurations, then when deploying the new VM with an ARM template you supply the VHD Uri link and it will use that as the drive for the VM.

 

ARM Templates for Almost Anything

The official Microsoft Azure GitHub repository contains sample ARM templates for almost every service in Azure:

https://github.com/Azure/azure-quickstart-templates

Leave a Reply

Your email address will not be published. Required fields are marked *