Following my previous article about resources deployment on Azure using terraform, I will now explain how you could deploy those resources through Azure DevOps.
You can find pipeline code on my Github repository
https://github.com/geralexgr/terraform-az-lin-win/blob/main/azure-pipelines.yml
To getting started you will need to install in your Azure DevOps organization the terraform extension provided from Microsoft DevLabs.
You can install it using the below link
Then you will have to create a resource group and a storage account inside. You will need the storage account to create a container that will hold you tfstate file.
Under your storage account select containers and add a new container. I created one named terraform that will be used in the pipeline.
Pipeline explanation:
Pipeline contains three tasks. The first task will install terraform tools. The second one will initialize terraform in your working directory. Based on the user input provided in the pipeline the appropriate resource will be deployed. The code on the github contains two separate directories, one for windows and one for linux machines.
The third task will apply your terraform configuration. The working directory is generated automatically from the provided parameter.
Terraform init variables:
- task: TerraformTaskV2@2 displayName: terraform init inputs: provider: 'azurerm' command: 'init' workingDirectory: '$(Build.SourcesDirectory)/${{ parameters.image }}' // your working terraform directory backendServiceArm: 'AzureMSDN' // azure devops service connection with your subscription backendAzureRmResourceGroupName: 'terraform' //resource group name backendAzureRmStorageAccountName: 'geralexgrstorageaccount' //storage account name backendAzureRmContainerName: 'terraform' //container inside storage account backendAzureRmKey: 'terraform.tfstate' //state file name inside your storage account
Resources deployed on Azure through the pipeline: