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:
- 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.
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:
Once you have created your project, we will work on the 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:
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.
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:
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.
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”,
Now on the Connect Tab use the classic editor to create a build pipeline using the ARM Templates.
Select your repository and Master Branch and then click on Continue
On the Template page, select “Empty Job”.
Edit the Pipeline Name.
On “Agent Job 1”, Add task to Agent Job 1, on the “search box” type Publish Build Artifact and add it.
On the Task “Publish Artifact: drop”, Change the display Name, for example: “Tier1-CI-AutomationAccount”
Now on “Path to publish” select the Folder of the Azure Resource.
Let’s kick off a build manually to ensure that we have a working build. Save and Queue,
Now provide a “Save comment” and then Save and Run as shown below:
You should be able to see the queue now:
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:
Here’s the screenshot from the Azure Pipeline for the storage account:
And the virtual network:
At the moment you should have 4 Pipelines, one pipeline per Azure resource as shown below:
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”.
Click on “New Pipeline”
and after that Select “Empty Job”.
Will change the name for “DEV”
Rename the name of the Release Pipeline from “New release pipeline” to your preferred name.
Add the artifacts previously created, they should be Vnet, Automation Account, Storage Account and Azure SQL Server. Click on add artifact.
Now select the build pipeline related to the resources:
Then click add:
Do the same for the rest of the resources:
On the tasks for our ‘Dev’ stage, add Task to the Agent Job. For ARM Templates, should you use “ARM template deployment”.
Set your Team Azure subscription, the Resource Group and Location. You need to provide authorization for the Azure subscription and the resource group:
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:
You can also override the template parameters, in this case manually provide the vnet name and subnet name:
Now save and click on create release:
Manually kick off a release and check that your VNET got deployed to your dev instance.
Now let’s take a look at the release pipeline:
If all goes as expected you should see the resources created:
Also you can verify the deployment on the Azure Portal:
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.