❄️CI CD Pipeline with Terraform Using Azure DevOps !!

Rupesh Jadhav
4 min readSep 11, 2022



For this tutorial, you will need:

  • AWS account
  • Azure DevOps Account
  • Git Account

⚜️Our objective:

1. Create Self Host Agent for Azure DevOps.
2. Create CI CD Pipeline with AZURE DevOps to Automate Deployment.
Lastly, all code should be in module blocks, not resource blocks.

Let’s get started — buckle up Chuck!!

1| Set Up Environment on Azure DevOps

First, Login in Azure DevOps Account

Create a Organization

Choose your Organization and Create new Project.

Click On New Project.

Then, Create a Self Host agent for Azure DevOps.

Click on Project Settings

Pipelines — Select Agent Pool

Click on Add Pool to Create self Host Agent.

2| Create a EC2 instance as self hosted agent for Azure DevOps

Choose Agent which we have Created in earlier steps.

Then Click on New Agent.

Select OS on which self host agent should host.

Now, we are hosting on Linux VM.

wget https://vstsagentpackage.azureedge.net/agent/2.210.0/vsts-agent-linux-x64-2.210.0.tar.gz

Unzip tar file

tar zxvf vsts-agent-linux-x64-2.210.0.tar.gz

Then Run ./config.sh & ./run.sh :


Now, Our self Hosted agent is ready !!

After hosting agent we have to install some other packages Like Git & Terraform.

sudo yum install git
sudo yum install -y yum-utils
sudo yum-config-manager --add-repo https://rpm.releases.hashicorp.com/AmazonLinux/hashicorp.repo
sudo yum -y install terraform

3| Creating CI CD Pipeline for Terraform :

  1. Create Pipeline for Terraform Init & Terraform apply:

Click on New pipeline.

Then, Click on Use the classic editor.

Select Project:

Select Repository to which we are using to deploy terraform code.

and Click Continue.

Click on Empty Job

From here, you will create our new Pipeline:

Select Agent Pool which we have created.

Search for Terraform Plugin and Add Terraform.

Select Provider & Command:

Create New service connection:


Click on Grant access permission to all pipelines.

Then Save.

Add Terraform Apply command.

Click on Triggers:

Select Branch on which we will push changes to Trigger Terraform Apply.

and Exclude Branch which trigger Destroy.

Then Save & queue.

Create New pipeline for Terraform Destroy.

Select Terraform Init Command.

Select Destroy Command :

Click on Triggers:

Select Exclude Branch on which we will push changes to Trigger Terraform Apply and Include Branch which trigger Terraform Destroy.

Our Terraform Apply & Terraform Destroy Pipeline Created Successfully!!


💠Keep Learning Keep Sharing💠



Rupesh Jadhav

ML Learner and Computer Vision/ AWS / DevOps Tools / Cloud Computing /