Introduction:-
Hello Learners, I am back with another blog. In today’s blog, we will learn about the ADO pipeline for terratest. In this blog, we will explore How we can write and run the test cases with the ado pipeline. If you like my blogs, you can read more blogs here.
Note:- I am working on the terratest blog series. So please follow my blog and learn about the terratest. You can check out this link for more blogs on the terratest.
Azure Pipeline:-
Azure DevOps (ADO) Pipelines is a cloud-based continuous integration and continuous delivery (CI/CD) platform provided by Microsoft Azure cloud. It is a powerful tool that allows developers to automate the build, test, and deployment processes for their applications.
Feature of Azure DevOps Pipelines:
- CI/CD Automation: Azure DevOps Pipelines enable developers to set up automated workflows to build, test, and deploy their applications with ease. This automation ensures that code changes are continuously integrated, tested, and delivered to production or staging environments.
- Multi-Platform Support: ADO Pipelines supports building and deploying applications on various platforms, including Windows, Linux, and macOS. It supports different programming languages also.
- YAML-Based Pipeline Definition: Pipelines in ADO are defined using YAML, a human-readable format.
- Integration with Azure Services: Azure DevOps Pipelines seamlessly integrate with other Azure services, such as Azure Repos, Azure Artifacts, Azure Functions, Azure Kubernetes Service (AKS), and more.
- Triggers and Scheduling: Pipelines can be triggered automatically on code commits, pull requests, or other events, ensuring continuous integration. Additionally, developers can schedule pipelines to run at specific times.
Pipeline:-
In this section, We will create an Azure DevOps pipeline to trigger the terratest to test the Private ACR. I have divided this pipeline into parts so that we can understand it in steps.
Trigger:-
In this section, we will set up the trigger point for the pipeline. For now, we have two trigger points we can trigger the pipeline manually or we can set up the pipeline with respect to the cron job.
This is the manual trigger:-
name: ACR Test using terratest
trigger: none
This is the cron job trigger:
trigger:
schedules:
- cron: "*/20 * * * *"
always: true
branches:
include:
- terratest-acr-module
In the trigger, we need to define the cron time. As per the about cron, this pipeline will trigger every 20 mins. In the last, I have defined the branch which is in the bold font.
Variable Group:-
As we need a few credentials or secret IDs or passwords in the pipeline. So we can not add them to the pipeline directly. So we will use the variable group for that. We will define them in the variable group and call them into the pipeline. You can create your variable group from here.

variables:
- group: Azure Credential
My variable group name is Azure Credential. So I am calling it.
Jobs:-
All the steps will be defined in this section. This Jobs section contains more than one job.
jobs:
- job: Run Terratest
Steps:-
In this section, you can create any task and step and define your flow.
steps:
- script: |
echo "This is second path", $(Build.SourcesDirectory)
mkdir "$(Build.SourcesDirectory)/terratest"
pwd
ls -R "$(Build.SourcesDirectory)"
ls -R "$(Build.SourcesDirectory)/terratest"
cd "$(Build.SourcesDirectory)/terratest"
ls -la
displayName: 'Create folder'
First of all, I am creating a folder in the ADO agent. So that I can perform my operation in that folder.
- checkout: self
displayName: 'Checkout terratest branch repo'
path: terratest
clean: true
Check out the code from the git repo in the Ado-Agent.
- script: |
curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash
displayName: 'Install Azure CLI'
- script: |
sudo apt-get update
sudo apt-get install -y unzip
curl -LO https://releases.hashicorp.com/terraform/1.5.0/terraform_1.5.0_linux_amd64.zip
unzip terraform_1.5.0_linux_amd64.zip
rm -rf terraform_1.*
sudo mv terraform /usr/local/bin/
terraform --version
pwd
displayName: 'Install Terraform'
- script: |
curl -LO https://golang.org/dl/go1.17.2.linux-amd64.tar.gz
sudo tar -C /usr/local -xzf go1.17.2.linux-amd64.tar.gz
rm -rf go1.*
export GOROOT=/usr/local/go
export GOPATH=$(HOME)/go
export PATH=$GOROOT/bin:$GOPATH/bin:$PATH
echo "export GOROOT=/usr/local/go" >> $(HOME)/.bashrc
echo "export GOPATH=$(HOME)/go" >> $(HOME)/.bashrc
echo "export PATH=\$GOROOT/bin:\$GOPATH/bin:\$PATH" >> $(HOME)/.bashrc
source $(HOME)/.bashrc
go version
pwd
displayName: 'Install Go'
Now I am adding the script to install the required package for the terratest like Azure CLI, Terraform, and Golang.
- script: |
az --version
pwd
az login --service-principal -u $appid) -p $(appsecret) --tenant $(TenantId)
echo "This is subscription id:=" $(ARM_SUBSCRIPTION_ID)
az account set --subscription $(ARM_SUBSCRIPTION_ID)
az account show
# az resource list --subscription $(ARM_SUBSCRIPTION_ID)
displayName: 'Check Azure CLI Version and Set up the Account'
I am authenticating with the azure account with the help of az cli.
Now, We have define all the all the step for the pipeline and now you can run the terratest code. So We will add the new script which can run the terratest:
- script: |
export PATH=$PATH:/usr/local/go/bin
cd test
go install github.com/gruntwork-io/terratest/modules/terraform
go mod init github.com/terratest/ACR-module-test
go mod tidy
# az account show
go test -v -timeout 50m
displayName: 'Run Terratest'
env:
TF_VAR_azure_client_id: $(appid)
TF_VAR_azure_client_secret: $(appsecret)
TF_VAR_azure_tenant_id: $(TenantId)
TF_VAR_azure_subscription_id: $(ARM_SUBSCRIPTION_ID)
This script can run the terratest and I am passing the environment variable because the terratest code will require these values while running the terraform.
It is a complete Azure pipeline to trigger the terratest. So you can also get the complete pipeline from here.
You can trigger the pipeline and will see the output below:

As you can see our pipeline has been run successfully.
Conclusion:-
In this blog, We have seen how we can create the ado pipeline for the terratest. I have divided all the steps and tasks into steps so that we can understand and I also attached the git URL. you can clone from there. If you like my blog then you can like this or if want to read more blogs then follow this link. and also check out the terratest official doc