Drift detection of IaC templates tracing with yor trace in Azure DevOps

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
L4 Transporter
No ratings

By Mikhail Bakhmetiev, Customer Success Engineer

 

Introduction

 

In this tutorial, we will cover the following objectives:

 

  • Create an Azure DevOps project
  • Add a self-hosted agent to run parallel jobs
  • Prepare the Remote State Backend
  • Connect to the Azure subscription
  • Create Pipelines with yor tracing capability
  • Deploy Infrastructure with the Pipelines

 

Create an Azure DevOps project

 

Prior to creating an Azure DevOps project, you should have an Application registered in Azure Portal to get the Application Client ID and the password, along with a storage account associated with a resource group. A storage account is used to store the Terraform state.

 

image12.png

Figure 01: Create the project in AZ DevOps org_PaloAltoNetworks

 

We need to create a repository where our Terraform IaC templates are hosted. For this tutorial purposes, we will create a vnet with Terraform that would have yor trace tags inserted.

 

In the “Repos” menu select “Import a repository” option

 

 
image1.png

Figure 02: Create new repo by importing from GitHub_PaloAltoNetworks

 

Import the GitHub repository with all necessary files from yor demo GitHub repo.

 

 
image10.png

Figure 03: Yordeomo repo with TF templates and pipeline files_PaloAltoNetworks

 

Add a self-hosted agent to run parallel jobs

 

If you create a new Azure DevOps organization using the Free tier, you won’t be able to execute parallel jobs to run pipelines on the Microsoft-hosted agent pool and will be getting an error: “No hosted parallelism has been purchased or granted”

 

Add an agent pool in the Project settings

 

 
image22.png

Figure 04: Add new Agent pool_PaloAltoNetworks

 

Self-hosted with all permissions granted

 

 
image4.png

Figure 05: Configure Agent pool details_PaloAltoNetworks


Click on the pool to add a self-hosted agent

 

image13.png

Figure 06: Select New Agent_PaloAltoNetworks

 

Install the agent on your local machine following the steps in the “New agent” wizard

 

 
image21.png

Figure 07: Follow Agent installation instructions_PaloAltoNetworks

 

At the configuration step you’ll need an Org Personal Access Token, to create one click on Org Settings

 

 
image15.png

image9.png

Figure 08: Create a new personal token_PaloAltoNetworks

 

Once the configuration is completed and the agent is launched, you should have an agent in status online, listening for the jobs

 

image2.png

Figure 09: Self-hosted agent is running and listening for the jobs_PaloAltoNetworks

 

Prepare the Remote State Backend

 

Create a variable group in the Pipelines Library called state-data with entries for the following:

 

BACKEND_RESOURCE_GROUP_NAME - Resource group name

BACKEND_AZURE_STORAGE_ACCOUNT_NAME - Storage account name

BACKEND_AZURE_STORAGE_ACCOUNT_CONTAINER_NAME - tfstate

BACKEND_AZURE_STORAGE_ACCOUNT_KEY_NAME - terraform.tfstate

BACKEND_TENANT_ID - Tenant ID

BACKEND_CLIENT_ID - Application Client ID from the service principal

BACKEND_CLIENT_SECRET - Secret from the service principal

BACKEND_SUBSCRIPTION_ID - Subscription ID

 

Set the:

BACKEND_CLIENT_SECRET

to a secret variable by clicking on the lock icon.

 

You can use Azure cli commands to retrieve required inputs

 

az login --use-device-code

az group list --query [].name

az storage account list --query [].name

az account show



Save the variable group.

 

In Project Settings create a service connection for Azure Resource Manager type 

 

image5.png

Figure 10: Select Azure Ressource Manager for new service connection_PaloAltoNetworks

 

Select “App registration or managed identity (manual)” for the Identity type and “Secret” for the Credential. Fill in all the necessary fields, save it as “yor” services connection, this exact name is used in the pipeline files

 

 
 
image11.png image20.png

Figure 11: Service Connection configuration_PaloAltoNetworks

 

Create Pipelines with yor tracing capability

 

First, we need to install the Terraform extension from the Visual Studio Marketplace.

 

TF extension at VS Marketplace

 

 
image16.png

Figure 12: Install Terraform extension_PaloAltoNetworks

 

In the Pipelines section, create the pipelines from existing repository files pr-plan.yml and merge-apply.yml respectively. 

 

 
 
image23.png

 

image7.png

Figure 13: Select existing pipeline files from the repo_PaloAltoNetworks

 

Both pipelines use objects created previously - the variable group “state-data” and “yor” service connection, as well as they rely on using a self-hosted agent “yor” created above.

 

Save both pipelines without running.

 

Rename the pipelines in the “Pipelines” menu to meaningful identifiers instead of the project name set as id by default.

 

 
image25.png

Figure 14: Rename the pipelines_PaloAltoNetworks

 

Add a build validation policy to the main branch in the repos menu, select the pr-plan pipeline with all defaults.

 

 
image14.png

Figure 15: Add a branch policy_PaloAltoNetworks

 

 
image17.png

Figure 16: Select the ’pr-plan’ pipeline and leave all the rest as default_PaloAltoNetworks

 

We place the yor installation script as well as yor cli command to tag the TF template in the pr-plan.yml pipeline file.

 

 
image19.png

Figure 17: Add your trace tagging to the pipeline file_PaloAltoNetworks

 

It is important to place the yor section before the tf plan file creation, to make sure the TF templates are tagged and will be deployed at TF apply stage along with resources being created with the TF templates.

 

Details on yor trace integration with different CI platforms can be found here.

 

Bridgecrew yor trace GitHub

 

Click on the state-data variable group. Click on Pipeline permissions and add the pr-plan and merge-apply pipelines to the group.

 

Deploy Infrastructure with the Pipelines

 

We will create a new branch, modify the code in it, commit, and create the pull request, this will trigger the pr-plan pipeline to execute.

 

Create new branch “vnet-deploy”.

 

 
image8.png

Figure 18: Create New Branch_PaloAltoNetworks

 

In the files, find the terraform.tfvars and set the correct value for the resource_group_name variable. Then commit to the “vnet-deploy” branch and create the pull request.

 

 
image18.png

Figure 19: Update Resource Group Name to the actual value_PaloAltoNetworks

 

 
image27.png

Figure 20: Create pull request_PaloAltoNetworks

 

Upon pr-plan pipeline execution, we will be able to complete the pull request and merge with the main branch, this in turn will trigger the merge-apply pipeline to execute creating the vnet in Azure cloud with yor trace tags.

 

image24.png

Figure 21: Complete the Pull Request_PaloAltoNetworks

 

Merge-apply is being executed on merge completion.

 

 
image3.png

Figure 22: Merge-apply pipeline is triggered_PaloAltoNetworks

 

The TF templates deployed the vnet with yor trace tags.

 

 
image26.png

Figure 23: vnet resource is created in Azure tagged by yor trace_PaloAltoNetworks

 

Checking the pr-plan pipeline jobs detail, we can see that the yor tags were applied to vnet in the main.tf file included in the tf plan file and then deployed.

 

image6.png

Figure 24: The yor trace tags are added to the main.tf file_PaloAltoNetworks

 

References

 

  1. Yor overview and use cases
    What is Yor?
  2. Yor installation
    Bridgecrew yor GitHub
Rate this article:
  • 555 Views
  • 0 comments
  • 0 Likes
Register or Sign-in
Contributors
Labels
Article Dashboard
Version history
Last Updated:
‎02-13-2025 11:30 AM
Updated by: