DevOps toolchain built under IaC

Cristian Fabres
2 min readJul 16, 2021
Photo by Florian Olivo on Unsplash

Working with a colleague, we were investigating about Infrastructure as Code (IaC) and their benefits. We started with CloudFormation (from AWS) and the first POC worked very well. Then we wanted to do the same in Azure so we decided to use a different IaC tool, Terraform.

Terraform looks good, you can start provisioning basic resources like static webapps, app services, app service plan, then scaling for more complex infrastructure.

Then we enjoyed adding environment variable to the terraform plan, so with this variable you can create the infrastructure for dev, qa and prod. Finally we started looking for the answer to this question: Can be possible to provision an Azure DevOps project’s creation?

This is key, because we can create the infrastructure and also the platform that provides and end-to-end DevOps toolchain for developing and deploying software.

Following is the step by step process we followed to create Azure DevOps through Terraform.

Download and install Terraform

Download terraform here: https://www.terraform.io/downloads.html

If you want to get started with Azure, go here: https://learn.hashicorp.com/collections/terraform/azure-get-started?utm_source=terraform_io_download

$ terraform --versionTerraform v0.14.2

Create the main.tf

Your main.tf looks like:

terraform {
required_providers {
azuredevops = {
source = "microsoft/azuredevops"
version = "0.1.5"
}
}
}
provider "azuredevops" {
org_service_url = "https://dev.azure.com/xxx"
personal_access_token = "xxxyyyzzz"
}
resource "azuredevops_project" "project" {
name = "my Terraform example"
description = "My Description"
visibility = "private"
version_control = "Git"
work_item_template = "Agile"
features = {
"boards" = "enabled"
"repositories" = "enabled"
"pipelines" = "disabled"
"testplans" = "disabled"
"artifacts" = "disabled"
}
}

Where org_service_url will be your valid organizacion service url and personal_access_token you will get it from: Azure DevOps → user settings → personal access tokens → click on “new token”.

Then finally click on Create. Make sure you copy the token. You will not be able to see it again.

Execute the IaC

The following are the commands that you need to execute in the same directory where is the main.tf file.

$ terraform init$ terraform apply -auto-approve

VOILÀ

You Azure DevOps under IaC was created automatically and looks like:

Destroy

If you want to destroy the DevOps project created, just run the following command:

$ terraform destroy -auto-approve

--

--