Building and deploying Azure Templates

Building and deploying Azure Templates

Provision Visual Studio 2019 Community Virtual Machine

The scenario:

Next month , you have to deploy a new Windows Server 2016 virtual machine for a project. At a recent tech conference, your manager heard a talk about using Azure Templates because they offer both documentation of what you deploy along with the ability to redeploy as needed.

You have always deployed Azure virtual machines via the Azure Portal but your manager wants to see you provide an Azure Template for the team to review at tomorrows team meeting. You need to download the template to show at the meeting.

Steps and requirements;  In this instance i used the Azure Portal to examine the components that make up an Azure QuickStart virtual machine template to gain a better understanding of the JSON template file structure. The following steps were taken to complete this lab.

  1. Launched Azure Portal and logged in with my lab credentials. (You can sign up for a free Azure account with limited resources or use a paid subscription with full access to Azure services.)
  2. Instead of going through the market place,
  3. i selected Virtual Machine and create, then virtual Machine
  4. choose ‘Windows Server 2016 Datacenter- Gen 2″

 

 

 

  1. Named the virtual machine VM1
  2. Supplied the user name and password.
  3. Before creating, the Disk , networking, management, advanced, tags were all reviewed and then create.

 

 

 

  1. completed the steps, downloaded the template and was able to Identify the Azure Templates Components, which are;

i. Parameters (31)

ii. Number of Variables (4)

iii .Resources (6)

1v. The schema and the version (“$schema”: “http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#”,

    “contentVersion”: “1.0.0.0”,)

As this lab was a simple templates, however i familiarize with Azure Resource Manager templates, which are JSON files defining the infrastructure and configuration of Azure resources. ARM templates makes it easy to deploy and manage resources consistently.

I looked into the default, deployment of incremental deployment and also the the complete deployment mode, for more complex deployments using deployment manager is the best practice.

 

Incremental deployment

Incremental Deployment: Examples of incremental deployment strategies include feature flags, A/B testing, canary deployment, and blue-green deployment.

When we do an incremental deployment, we can define this in two places, one is in our template under the properties mode, we can specify that we want this template to always be deployed in an incremental or complete mode

Two, it can also be done via PowerShell by doing a new AzResourceGroupDeployment, we can set the mode to incremental. Because incremental is the default mode, when you don’t specify a deployment mode, by default it will take incremental.

For instance we have a resource group with 3 resources in it, Resource A,B,C

and we write a template to manage this resource group. Lets say we forgot Resource C and we added the new Resource D

Resource A,B,D and we run this incremental deployment.

In this instance we will be having 4 resources. because an incremental template never deletes an existing resource. If there is an already resource there, it won’t delete or remove an existing resource.

 

Complete deployment 

Complete deployment refers to the process of deploying all the resources defined in the template to an Azure environment simultaneously. It is an optional deployment mode that’s available via PowerShell or the JSON template. Here you can specify that you want to take a template and use the template as the gold standard of what should be deployed.

 

Let’s take for instance, we have Resource A,B,C and our templates has A,B and D resources. When we run a complete deployment,  C will be deleted, and we will have A,B and D.

That is why it’s important to be careful here as a user can mistakenly wipe out a whole important environment unknowingly because they thought they were making a change.

Let’s consider an example where you have an ARM template that defines an Azure Virtual Network, a Network Security Group (NSG), and a Virtual Machine (VM). When you initiate a complete deployment with this template, Azure will attempt to create all these resources at once:

 

  • Incremental Deployment: Examples of incremental deployment strategies include feature flags, A/B testing, canary deployment, and blue-green deployment.
  • Complete Deployment: Complete deployment involves synchronizing all changes into a single release without any specific deployment strategies.

In summary, incremental deployment is a safer and more controlled approach, allowing for iterative improvements and early detection of issues. On the other hand, complete deployment is more straightforward and may be suitable for smaller projects with less complexity. The choice between the two strategies depends on the project’s size, complexity, risk tolerance, and the need for early feedback and validation.

 

 

Deploying Azure Templates 

In this lab, i deployed a virtual machine into a storage account, it will deploy a network security group, a public IP,  a network interface and a network. Along with an OS disk and a data disk.

 

 

 

The above diagram shows that the deployment was completed. You can also verify by checking the bell at the azure menu.

 

The diagram below will show a deployment of windows 2019 Virtual machine, with modified template and additional data disk using the Standard_D2s-v3 instance type

 

 

Deployment Tools.

  1. Visual Studio Code

 

Azure Resource Manager with Visual Studio code is pretty robust way to manager templates and it’s best practice way to do this. as basically tells you if there ia problem with the code you are running. Good news, Visual studio Code is free

 

2 . Azure Cloud Shell

Azure Cloud Shell is a cloud-based, interactive shell environment provided by Microsoft Azure. It enables users to manage and interact with their Azure resources using the command-line interface (CLI) or PowerShell, directly from the Azure portal or through the Microsoft Azure mobile app. You can also access it via Docs, maybe you are looking at how to deploy a particular function and it’s something you have not done before, there are commands right in the documentations on how to execute new workloads, so you can execute those against your subscription right from the documentations.

One of he beauty of Azure Cloud Shell is upon setup, it ask you to setup a storage account which enables you to store all of your scripts.

Benefits of Azure Cloud Shell includes; Convenience, Pre-installed Tools, Persistent Storage, No Local Installation Needed, Automatic Authentication
It’s a scripting language, which can easier for developers to read and write.
Negatives, not capable of the same power as Azure templates for life-cycle management. Azure CLI may be better suited for a rapid development environment creation.
Dependency on Azure Portal, Data Privacy Concerns, Limited Resources.

 

Deploying Azure Templates with Visual studio code.

 

In this lab, using Azure virtual machine with visual studio code for a prebuilt template that will be deployed from the Azure portal. This was done by logging in and accessing Github to download the template and deploy a Linux virtual machine into an existing resource group.

 

One of the task in this lab is to modify the network security group in our virtual machine to allow SSL inbound.

 

Scenarios:

Developers need a Linux VM with port 443 allowed inbound. They tested with a VM built from the Azure Quickstart template 01-vm-simple-linux, which has everything except the port 443 allowance. We will use Visual Studio Code to modify the template prior to deployment.

Steps for this lab, Provision Visual Studio 2019 Community Virtual Machine , Click Home > + Create a resource.

Search for “Visual Studio 2019 Community (latest release) on Windows 2019 Server (x64)”. Click Create. Select the provided Resource Group.

Enter Virtual machine name “VS-Studio-01”. For Region, select (US) West US. For Availability Options, No infrastructure redundancy

Task

  1. Provision Visual Studio 2019 Community Virtual Machine
  2. Connect to visual studio virtual machine and add plugins
  3. Download and modify “101-vm-simple-linux” template from GitHub
  4. Configure Azure Cloud Shell
  5. Configure Template storage and upload
  6. Deploy Azure Template via Azure cloud shell
  7. Deployment Validation

Here i noted that the security type accepted was standard.

 

Deployment Completed.

 

Download the RDP file.

Connected to RDP windows server 2019 with visual studio community ( logged in with the admin credential we created earlier) through the downloaded RDP file

Installed Azure CLI and PowerShell and Azure Resource manager tool.

The diagram below shows how the downloaded template was modified.

 

Configure Azure cloud Shell so we can upload the template and execute them.

Now you can see OUR virtual machine VS-V01

 

 

Now we have our URL for deployment

Resource group so we can get our resource group name on the screen

Deployment was successful

To Validate that our Deploy was successful. We can export this template and redeploy it another time if we want to.

 

Building and deploying Azure templates involves creating declarative definitions of Azure resources using ARM templates in JSON format. These templates enable consistent and repeatable deployments, supporting parameterization for customization. Thorough testing, version control, and CI/CD integration are essential for efficient and secure deployment. By using Azure templates, organizations can streamline infrastructure provisioning, achieve scalability, and embrace a cost-effective and automated approach to cloud resource management.

 

Leave a Reply

Close Menu