Dave Rendón Microsoft Azure MVP, embracing and fostering tech intensity to benefit society and thrive in a digital world.

Using Azure Devops to deploy ARM templates

5 min read

AzureBacktoSchool-azure-devops-deploy-ARM-templates

Hello, everyone, this article, part of the Azure back to school initiative, will focus on using Azure Devops to deploy ARM templates.

The goal on this article is to introduce you to the Azure DevOps tooling and some common DevOps practices to deploy your Azure Resource Manager templates.

Will use a set of different resources, separated in Tiers, and implement concepts of modular programming, with an emphasis on showing how Azure DevOps can help you on your DevOps journey so that you can apply this in your environments.

DevOps is a very broad topic and you have lots of choices when it comes to the tools that you use. 

So let’s take a look at the pre-requisites:

Pre-requisites:

  • An active azure subscription
  • An azure devops account
  • Visual Studio Code with the ARM extension
  • Git installed on your local machine

Once you have this tools in place let’s deep dive into the step by step process. We will start with Azure Devops.

Azure Devops.

Let’s sign in to azure devops – dev.azure.com

I’ve previously created an organization called “azureback2school” and created a new project with the same name as shown below:

01-azure-devops-deploy-ARM-templates

Once you have created your project, we will work on the Azure Repos.

Azure Repos.

For those who are new to Azure Devops, Azure Repos is a set of version control tools that you can use to manage your code. Whether your software project is large or small, using version control as soon as possible is a good idea.

You could think of scenarios where a Dev Team develops and maintain the application at the same time that the IT Team works on the infrastructure side.

When you create your project in Azure DevOps, it creates a default repository for you in Azure Repos.

And here’s a link on how to initialize a repo: http://bit.ly/azure-repos

If you go to the Azure Repos section you will find that there are multiple options to initialize your repo, you could either clone the Azure Repo to your local machine, push an existing repository from command line or import a repository:

02-azure-devops-deploy-ARM-templates

Now, a huge benefit of using Azure Devops is that you can divide automation assets into logical parts like databases, networks, storage etc.

Since we are going to deploy ARM templates, it is suggested to work with Azure Devops using Modularization of your ARM templates as it allows you to:

  • Reuse of components.
  • Manage and maintain your code.
  • Sub-divide work and responsibilities across teams.
  • Troubleshooting.

In order to work with modularization it is recommended to identify what Azure resources have dependencies and create ARM templates based on those dependencies and keep a folder structure that facilitate the management of your environment.

Let’s Check the Reference Diagram:

03-azure-devops-deploy-ARM-templates

You can create ARM Templates using Visual Studio Code with the ARM extension. You could start developing then your resources per Tiers

For instance you could have a Tier1 resources folder where you include your Vnet, Automation Account, Azure SQL Server and Storage Account, etc.

A Tier 2 where you include the application management components and a Tier 3 which would be the application code.

So as you can see Azure devops will help you build the environment you need to deploy and provide this source control and versioning tools to better manage your deployment.

Once you have all your ARM templates ready then Commit the code and push to the Azure repo.

You should be able to go to the Azure DevOps site and under Azure Repos see your folder structure.

04-azure-devops-deploy-ARM-templates

Great, we now have some infrastructure code, let’s build it. In DevOps we automate this process using something Continuous Integration using Azure Pipelines to automate our build process.

Go to Pipelines, then click on “New Pipeline”,

05-azure-devops-deploy-ARM-templates

Now on the Connect Tab use the classic editor to create a build pipeline using the ARM Templates.

06-azure-devops-deploy-ARM-templates

Select your repository and Master Branch and then click on Continue

07-azure-devops-deploy-ARM-templates

On the Template page, select “Empty Job”.

08-azure-devops-deploy-ARM-templates

Edit the Pipeline Name.

09-azure-devops-deploy-ARM-templates

On “Agent Job 1”, Add task to Agent Job 1, on the “search box” type Publish Build Artifact and add it.

010-azure-devops-deploy-ARM-templates

On the Task “Publish Artifact: drop”, Change the display Name, for example: “Tier1-CI-AutomationAccount”

011-azure-devops-deploy-ARM-templates

Now on “Path to publish” select the Folder of the Azure Resource.

012-azure-devops-deploy-ARM-templates

Let’s kick off a build manually to ensure that we have a working build. Save and Queue,

013-azure-devops-deploy-ARM-templates

Now provide a “Save comment” and then Save and Run as shown below:

014-azure-devops-deploy-ARM-templates

You should be able to see the queue now:

015-azure-devops-deploy-ARM-templates
016-azure-devops-deploy-ARM-templates

Now let’s build an Azure Pipeline for rest of the Azure Resources.
You should have one build for each Tier1 Azure Resource.

Here’s the screenshot from the SQL Server and database:

017-azure-devops-deploy-ARM-templates

Here’s the screenshot from the Azure Pipeline for the storage account:

018-azure-devops-deploy-ARM-templates

And the virtual network:

019-azure-devops-deploy-ARM-templates

At the moment you should have 4 Pipelines, one pipeline per Azure resource as shown below:

020-azure-devops-deploy-ARM-templates

In DevOps after we automate our build process, we want to automate our release process, we do this with a technique called Continuous Delivery.

In Azure DevOps we use an Azure Pipeline to release our infrastructure and application.

You start using Azure Pipelines releases by authoring a release pipeline for your application. To author a release pipeline, you must specify the artifacts that make up the application and the release pipeline.

An artifact is a deployable component of your application. It is typically produced through a Continuous Integration or a build pipeline.

You define the release pipeline using stages, and restrict deployments into or out of a stage using approvals. You define the automation in each stage using jobs and tasks. 

Also You could use variables to generalize your automation and triggers to control when the deployments should be kicked off automatically

Create a new Release Pipeline, go to Pipelines, then “Releases”.

021-azure-devops-deploy-ARM-templates

Click on “New Pipeline”

022-azure-devops-deploy-ARM-templates

 and after that Select  “Empty Job”.

023-azure-devops-deploy-ARM-templates

Will change the name for “DEV”

024-azure-devops-deploy-ARM-templates

Rename the name of the Release Pipeline from “New release pipeline” to your preferred name.

025-azure-devops-deploy-ARM-templates

Add the artifacts previously created, they should be Vnet, Automation Account, Storage Account and Azure SQL Server. Click on add artifact.

026-azure-devops-deploy-ARM-templates

Now select the build pipeline related to the resources:

027-azure-devops-deploy-ARM-templates

Then click add:

028-azure-devops-deploy-ARM-templates

Do the same for the rest of the resources:

029-azure-devops-deploy-ARM-templates

On the tasks for our ‘Dev’ stage, add Task to the Agent Job. For ARM Templates, should you use “ARM template deployment”.

030-azure-devops-deploy-ARM-templates

Set your Team Azure subscription, the Resource Group and Location. You need to provide authorization for the Azure subscription and the resource group:

031-azure-devops-deploy-ARM-templates

Now provide  the parameters of ARM Templates with the respective values. Specify the path or a pattern pointing to the Azure Resource Manager template. Select the template for the Vnet:

032-azure-devops-deploy-ARM-templates

You can also override the template parameters, in this case manually provide the vnet name and subnet name:

033-azure-devops-deploy-ARM-templates

Now save and click on create release:

034-azure-devops-deploy-ARM-templates

Manually kick off a release and check that your VNET got deployed to your dev instance.

035-azure-devops-deploy-ARM-templates

Now let’s take a look at the release pipeline:

036-azure-devops-deploy-ARM-templates

If all goes as expected you should see the resources created:

037-azure-devops-deploy-ARM-templates

Also you can verify the deployment on the Azure Portal:

038-azure-devops-deploy-ARM-templates

Along this article we have reviewed how you can deploy your ARM templates using Azure Devops and best practices to create build pipelines and release pipelines to provide better control of your environments.

Dave Rendón Microsoft Azure MVP, embracing and fostering tech intensity to benefit society and thrive in a digital world.

2 Replies to “Using Azure Devops to deploy ARM templates”

  1. Thanks a lot for publishing this article. This is the method enterprises uses but I was wondering, why there is no write up available for it. Thanks a lot for putting this together.

    1. Hi Lovnish,

      Thank much for taking the time to read this article and couldn’t agree more with you, there’s a need for more specific documentation that outline this practices. 👍

      Cheers!

Leave a Reply

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