Search
StarWind is a hyperconverged (HCI) vendor with focus on Enterprise ROBO, SMB & Edge

[Azure DevOps] Terraform deployment with Azure DevOps – Part 1

  • April 9, 2019
  • 8 min read
Cloud and Virtualization Architect. Florent is specializing in public, hybrid, and private cloud technologies. He is a Microsoft MVP in Cloud and Datacenter Management and an MCSE in Private Cloud.
Cloud and Virtualization Architect. Florent is specializing in public, hybrid, and private cloud technologies. He is a Microsoft MVP in Cloud and Datacenter Management and an MCSE in Private Cloud.

 

Create the DevOps project

1. Create the DevOps project

Azure DevOps (previously VSTS) allows you to automate the deployment of resources, whether ARM template (JSON), PowerShell, CLI, Terraform, etc.

Today, I’m going to focus on the integration with Terraform. Be careful, I’ll not go into Terraform details in this article, so you need to know the technology.

The pricing for Azure DevOps is available here:

https://azure.microsoft.com/en-us/pricing/details/devops/azure-pipelines/

By default, you’ve 5 users free.

Before starting, make sure you’ve an Azure DevOps organization in your subscription:

make sure you’ve an Azure DevOps organization in your subscription

Open via the URL your Azure DevOps and create a new project by clicking on Create project:

Open via the URL your Azure DevOps and create a new project by clicking on Create project

Give it a name and click on Create:

Give it a name and click on Create

When the project is created, you can invite people, etc.:

When the project is created, you can invite people, etc.

On the left, go into Repos > Files and add one or more files in the directory. You can add a README for example, to initialize the project, by clicking on Initialize:

go into Repos > Files and add one or more files in the directory

When the initialization is finished, you’ll have at least one file in your repository:

you’ll have at least one file in your repository

Here, create a folder, with 2 files, main.tf and variables.tf:

create a folder, with 2 files, main.tf and variables.tf2. Terraform code

With following Terraform code, I’ll deploy 1 VNet in Azure, with 2 subnets. As you can see, for some variables, I’m using __ before and after the variable. It’s to be able to use variables, directly in Azure DevOps. The code use dis the following :

Main.tf

Variables.tf

3. Create your first build

We will now create the build, which will check if resources have been modified in a particular folder, and thus, create a new build for our future release. Click on Pipelines > Builds > New Pipeline:

Click on Pipelines > Builds > New Pipeline

Here, choose where sources are located and validate:

choose where sources are located and validate

Choose the template that you want to use, empty job for me:

Choose the template that you want to use

Give a name, choose a pool where an agent is installed. This pool can be deployed on one of your VMs, to limit costs:

Give a name, choose a pool where an agent is installed

Add a job with type Copy Files. Give a name, choose the folder where you created your files main and variables, and choose to copy all content. The target folder must be the following: $(build.artifactstagingdirectory)/Terraform

Add a job with type Copy Files

Add a job with type Publish Build Artifacts and leave it with default parameters:

Add a job with type Publish Build Artifacts and leave it with default parameters

Click now on Triggers to activate the CI (Continuous Integration) to launch this build, after each file modification that exists in the master branch:

Click now on Triggers to activate the CI (Continuous Integration) to launch this build

Save and execute the build:

Save and execute the build - img

Save and execute the build

After few seconds, our build was executed correctly:

After few seconds, our build was executed correctly

You will receive an email to tell you that everything works well with the last build:

You will receive an email to tell you that everything works well with the last build

And with CI activated, the reason of the execution with this new build is Continuous integration:

And with CI activated, the reason of the execution with this new build is Continuous integration

In the next article, we will see how to build our first release to deploy the Terraform template.

Hey! Found Florent’s article helpful? Looking to deploy a new, easy-to-manage, and cost-effective hyperconverged infrastructure?
Alex Bykovskyi
Alex Bykovskyi StarWind Virtual HCI Appliance Product Manager
Well, we can help you with this one! Building a new hyperconverged environment is a breeze with StarWind Virtual HCI Appliance (VHCA). It’s a complete hyperconverged infrastructure solution that combines hypervisor (vSphere, Hyper-V, Proxmox, or our custom version of KVM), software-defined storage (StarWind VSAN), and streamlined management tools. Interested in diving deeper into VHCA’s capabilities and features? Book your StarWind Virtual HCI Appliance demo today!