Terraform Deployment with Effective Pipeline Patterns in DevOps — Azure

DevOpsWithYoge
5 min readJan 11, 2024

--

Hi Everyone , Excited to share you guys with yet another article with deployment patterns for terraform. In this article exclusively I have considered the `Azure` + Terraform Combination for explanations.

This gives a deployment architectural overview in pipeline design which can act as microservice in state file management.

Using variables as a smart move to deploy infra’s clean and also it provides the basic terraform commands which can be used in the pipeline.

Intended Audience:

This blog is specifically for audience who have good knowledge on terraform and pipeline deployments in DevOps.

Topics Covered:

  1. Smart usage of variables

2. Basic terraform commands and their usages

3. Terraform Deployment Designs with DevOps Pipeline’s

Smart usage of variables

In the previous article I have shared the examples of usage of variables and declaration standards for it.

https://medium.com/@allaboutazure/terraform-azure-coding-naming-convention-and-resource-creation-patterns-91e1e8e45283

Here I would like to share how to make use of *.tfvars effectively for deployment.

Simple Example :

Create a log analytics workspace in azure for Dev, Stage and Prod.

Github link : https://github.com/AllAboutAzure/Terraform-materials/tree/main/smart-usage-of-variables

In the above example we have seen that with variables folder you can find the environment specific variable files.

If you want to deploy it you can deploy it using plan and apply mentioning the correct var file .

terraform plan -var-file="dev.tfvars"
terraform apply -var-file="dev.tfvars"

and so on for stage and prod.

Basic terraform commands and their usages

As the above chapter its also important to know the significance of the terraform commands and execute them in

Azure login through CLI:

Azure CLI commands to login through CLI

Terraform Commands

The above Two Chapters forms the basis for the pipeline deployment in the blog.

Terraform Deployment Designs with DevOps Pipeline’s

Note: The customer Expectations which I have mentioned are not much deep it is considered to be simple so that even beginner can understand the purpose and it motivates them to learn more with Pipelines and terraform.

This gives a micro level usage of pipeline + terraform Azure. this can be extended for the all the three patterns which are discussed below.

Github : https://github.com/AllAboutAzure/Terraform-materials/tree/main/terraform-template-micros

Pattern 1: (Small Scale Deployments)

Using this pattern the small level of resource deployment can be done.

Customer Expectation:

Dark is a customer who came with a requirement for deployment of Azure resources (log analytics workspace) which can store the OnPrem hosted Virtual machine monitoring data.

Dark wants to store all the monitoring logs in custom created tables in the log analytics workspace.

Possible Solution:

Through the Pattern 1 you can easily deploy the log analytics workspace in azure cloud across three different environments.

Fig 1.0 Pattern 1 Design

Pattern 2: (Medium Scale Deployments)

if its a medium level resource deployments then we can make use of the concept of modules in terraform and deploy the resources .

Customer Expectation:

KETO is a customer who has their development across two different regions across the world.

They wanted to deploy the different types of azure resource in each different regions:

Backend dev Team -> eastus -> needs Api management , application gateway .

Frontend dev Team -> northuk -> needs azure webapp with node.

For development it will be two seperate dev and stage environment and while deployment is done in production the resource deployment should go with single production subscription.

Possible solution:

For the development purpose both backend and frontend team can have requested infra deployed .

For this solution its appropriate to use modules to create resources.

This will pave a way to use (dev/stage/prod)*.tfvars to create necessary resource creation variables in each locations separately or together.

Fig 1.1 Pattern 2 Design

Pattern 3: (Large Scale Deployments)

This provides us a three tier architecture for secure deployment and it is similar like a microserivce architecture in deployment style.

This is influence purely from the Microsoft’s Official Documentation on landing zone.

https://learn.microsoft.com/en-us/azure/architecture/landing-zones/terraform/landing-zone-terraform

Customer Expectation:

RETRO is a musical instrument selling company is selling their products across the world .

they wanted to make of azure infrastructure for their cloud Journey . so they need help in creating a complete integration service in cloud.

Possible Solution:

To create a complete integration service in Azure Cloud the below pattern paves a way to structure the resource creations in three layers and make the solution deployments as microservices.

Fig 1.2 Pattern 3 Design

--

--

DevOpsWithYoge

An enthusiastic DevOps professional ,I would like to help/share Azure Cloud aspirers and learners to know the aspect where Azure Cloud meets the realworld.