To get started read my previous blogs

Log in to your Azure DevOps or take a look at my public project. How to create Azure DevOps account read my blog Create Azure DevOps account.

Clone my repo with Terraform configuration we created in this blog Create Azure Resource Group using Terraform or use your own repo with Terraform configuration

git clone https://[email protected]/sergeydotnet/TerraformConfiguration/_git/WebApp

If you are using my repo the structure looks like this

Structure

Add new folder and call it builds

Add new file to this folder and call it build-pipline.yaml

build-pipeline.yaml

Now we have to ways: start to write all YAML configuration from scratch using documentation or just use build we created in my previous blog and copy YAML configuration.

I am a lazy person, so I am choosing of course the second choice. Go to my public project then Pipelines -> Builds and find my build called TerraformConfiguration

Click on Edit

TerraformConfiguration

Click on View YAML

Click on Copy to clipboard

Paste the code to the build-pipeline.yaml file

Clean the auto generated code. The file should be like this

steps:
- task: charleszipp.azure-pipelines-tasks-terraform.azure-p[email protected]
  displayName: 'Use Terraform 0.11.11'
  inputs:
    terraformVersion: 0.11.11

- task: [email protected]
  displayName: 'Download secure file'
  inputs:
    secureFile: 'terraform.tfvars'

- task: [email protected]
  displayName: 'Copy Files to: $(Build.SourcesDirectory)'
  inputs:
    sourceFolder: $(Agent.TempDirectory)
    targetFolder: $(Build.SourcesDirectory)

- script: 'terraform init'
  displayName: 'Terraform init'

- script: 'terraform apply -auto-approve'
  displayName: 'Terraform apply'

- task: [email protected]
  displayName: 'Delete files from $(Build.SourcesDirectory)'
  inputs:
    SourceFolder: '$(Build.SourcesDirectory)'
    Contents: '**'

This is YAML code representation of  this

Build pipeline

And detailed explanation can you read here Using Terraform with Azure DevOps.

Save the code, commit and push your changes.

Go to Pipelines -> Builds

Pipelines

New build pipeline

New build pipeline

Choose Use the visual designer

Use the visual designer

Choose your repo and branch

Select a source

and click Continue

Choose YAML and click on Apply

Give a good Name and choose an agent pool. So far so good. Actually exactly the same steps we did in my previous blog Using Terraform with Azure DevOps.

YAML

Choose your YAML file. If you follow along the file should be under the builds folder

Select path

Click on OK

Now we click on Triggers to enable or disable continuous integration.

Triggers

I don't need continuous integration, so I just choose Disable continuous integration. Obviously you can define all this settings in the YAML file, but I think it's better to do it in the Azure DevOps.

Save & queue the build pipeline.

Don't forget to upload your terraform.tfvars file to Library as described in my previous blog Using Terraform with Azure DevOps.

Check the logs

Logs

And Azure Portal

Resource groups

Now we learned how to work with Terraform and Azure DevOps.

Next we are going to create a real world Infrastructure as a Code configuration where we are going to create App Service Plan with to App Services and SQL Server with SQL database. Keep reading!


Links in this blog

Create Azure Resource Group using Terraform blog

Using Terraform with Azure DevOps blog

Using Terraform with Azure DevOps using YAML blog

Create Azure DevOps account blog

My public project

My Repo with YAML configuration