Active-Active Infrastructure using Terraform and Jenkins on Microsoft Azure

In this blog, we will create an active-active infrastructure on Microsoft Azure using Terraform and Jenkins.

Prime Reasons to have an active-active set-up of your infrastructure

Disaster Recovery:

Disaster recovery (DR) is an organization’s method of regaining access and functionality to its IT infrastructure after events like a natural disaster, cyber attack, or even business disruptions just like during the COVID-19 pandemic.

  • Ensure business resilience
    No matter what happens, a good DR plan can ensure that the business can return to full operations rapidly, without losing data or transactions.
  • Maintain competitiveness
    Loyalty is rare and when a business goes offline, customers turn to competitors to get the goods or services they require. A DR plan prevents this.
  • Avoid data loss
    The longer a business’s systems are down, the greater the risk that data will be lost. A robust DR plan minimizes this risk.
  • Maintain reputation
    A business that has trouble resuming operations after an outage can suffer brand damage. For that reason, a solid DR plan is critical.

Latency Improvement:

The closer your backend origin is to end-users, the better the experience. Having your services deployed in multi-region can reduce latency, thus serving the content faster to users and having more return customers percentage on your service.

Cloud Platform Used:


Azure is a cloud computing platform and an online portal that allows you to access and manage cloud services and resources provided by Microsoft. These services and resources include storing your data and transforming it, depending on your requirements. To get access to these resources and services, all you need to have is an active internet connection and the ability to connect to the Azure portal.


Tools used for Infrastructure Set-Up


Jenkins is an open-source continuous integration/continuous delivery and deployment (CI/CD) automation software DevOps tool written in the Java programming language

It is a free source that can handle any kind of build or continuous integration. You can integrate Jenkins with a number of testing and deployment technologies.


Terraform is an infrastructure as code (IaC) tool that allows you to build, change, and version infrastructure safely and efficiently. This includes both low-level components like compute instances, storage, and networking, as well as high-level components like DNS entries and SaaS features.


Active-Active Infrastructure with Azure Cloud:

The main purpose of this blog is to create a multi-region infrastructure on Azure, we will achieve this by using the multi-directory structure for our terraform code, like the one in the picture below:

Directory Structure of our Code:

Terraform and Jenkins Pipeline Code

For creating the infrastructure, we will use sample terraform code for multi-region deployment, this code contains all the required resources to provision a multi-site virtual machine and for creating the pipeline we will use the sample Jenkinsfile, which will create a pipeline for the terraform code, that takes to apply and destroy as input and runs the terraform code accordingly.

Using the above sample terraform code, the following resources will be created

  • Resource Group
  • Virtual Network
  • Subnet
  • Public IP
  • Network Interface
  • Security Group
  • Virtual Machine

After running the Jenkins job (Jenkinsfile in sample code), our pipeline will look like this

Once the pipeline is successful, we will be able to see the infrastructure deployed in multi-region on Azure Portal.


This is one of the ways which can be used to deploy multi-region infrastructure using Jenkins and Terraform on Azure Cloud, if you need your infrastructure to be fault-tolerant, have low latency, grow user base, comply with data privacy laws and regulations, etc. then go for multi-region deployment as shown above.

Blog Pundits: Shweta Tyagi and Sandeep Rawat

OpsTree is an End-to-End DevOps Solution Provider.

Connect with Us

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: