A close up of a map Description automatically generated

After seeing how to create our first build with a terraform file in the part 1, we will see how to create a release to deploy our Terraform template.

Now that we’ve our build, select Pipelines > Releases and click on New pipeline:

Pipelines > Releases and click on New pipeline

Select Empty job in next screen:

wp-image-11951

Rename your pipeline, choose the build source pipeline and as version, select the lastest build available, to integrate our CI/CD:

wp-image-11952

Click on the lightning and activate the CD (Continuous Deployment):

A screenshot of a cell phone Description automatically generated

Don’t forget to save. Open now your Stage 1 and add the following tasks, by clicking on the + :

  • Azure CLI
  • Azure PowerShell
  • Replace Tokens
  • Run Terraform
  • Run Terraform
  • Run Terraform

Be careful, Replace tokens and Run Terraform must be installed from the store (free) before using them:

A screenshot of a cell phone Description automatically generated

We’ll now configuring each step. For the first step, Azure CLI, you can rename it, and after, add a subscription, with a service principal account, that has rights to deploy resources in the subscription:

wp-image-11955

Choose Inline script and use the following script, to create the resource group and the storage account that we will use to store our tfstate file, that gives us an overview of the deployment and give the possibility to continue the deployment after each modification:

You should have this:
A screenshot of a cell phone Description automatically generated

Open the second step, Azure PowerShell, and give it a name. Choose the Azure Connection Type => Azure Resource Manager and the subscription that you created previously. Choose Inline Script and insert the following script, to get the access key of the storage account:

Choose to use the last installed version of Powershell and Save. You should see this:

A screenshot of a cell phone Description automatically generated

For the third step, Replace Tokens, modify Target files by including every .tf files and, in Advanced, modify Token prefix and Token suffix by __ that we included in main.tf file. With that, it will take variables of our release, directly in Azure DevOps and not in the variables.tf file. You should see this:

A screenshot of a cell phone Description automatically generated

In the fourth step, Run Terraform, provide a name, choose the path to the template (the artifact, built in the build) by clicking on … and provide the argument init. Check the box to Install terraform, with the latest version, and check the box to use an Azure service principal, and choose your Azure subscription:

A screenshot of a cell phone Description automatically generated

In the fifth step, it’s the same as the fourth step, except for the argument, it’s plan instead of init:

A screenshot of a cell phone Description automatically generated

For the last step, it’s same as before, except for argument part. You must replace plan by apply -auto-approve:

A screenshot of a cell phone Description automatically generated

Save. Navigate to the Variables tab and click on Add:

A screenshot of a cell phone Description automatically generated

Add the following values, with your own values:

  • location
  • resource_group
  • terraformstorageaccount
  • terraformstoragerg

A screenshot of a cell phone Description automatically generated

My subscription is empty as you can see below:

A screenshot of a cell phone screen with text Description automatically generated

To start the deployment, just modify the variable file in the repo. When you’ll commit the file, the build will start (CI) and when the build is done, the release will be created (CD):

wp-image-11965

A screenshot of a cell phone Description automatically generated

A screenshot of a cell phone Description automatically generated

A screenshot of a cell phone Description automatically generated

A screenshot of a cell phone Description automatically generated

wp-image-11970

A screenshot of text Description automatically generated

A screenshot of a cell phone Description automatically generated

StarWind Virtual SAN eliminates any need for physical shared storage just by mirroring internal flash and storage resources between hypervisor servers. Furthermore, the solution can be run on the off-the-shelf hardware. Such design allows StarWind Virtual SAN to not only achieve high performance and efficient hardware utilization but also reduce operational and capital expenses.

Learn more about ➡ StarWind Virtual SAN

As you can see, everything worked fine. And on Azure, I’ve all of my resources deployed:

wp-image-11973

wp-image-11974

As you can see, it’s very easy now to deploy Terraform template with automation from beginning to end. It works with modifications and so on, so during the build/release of your change, you can do other work or drink a coffee 🙂

Views All Time
19
Views Today
34
Appreciate how useful this article was to you?
1 vote, average: 5.00 out of 51 vote, average: 5.00 out of 51 vote, average: 5.00 out of 51 vote, average: 5.00 out of 51 vote, average: 5.00 out of 5
5 out of 5, based on 1 review
Loading...
Back to blog
The following two tabs change content below.
Florent Appointaire
Florent Appointaire is Microsoft Engineer with 5 years of experience, specialized in Cloud Technologies (Public/Hybrid/Private). He is a freelance consultant in Belgium from the beginning of 2017. He is MVP Cloud and Datacentre Management. He is MCSE Private Cloud and Hyper-V certified. His favorite products are SCVMM, SCOM, Windows Azure pack/Azure Stack and Microsoft Azure.