To get started read my previous blogs
- Create Azure Resource Group using Terraform - to create your first Terraform configuration
- Using Terraform with Azure DevOps - detailed description how to use Azure DevOps
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://firstname.lastname@example.org/sergeydotnet/TerraformConfiguration/_git/WebApp
If you are using my repo the structure looks like this
Add new folder and call it builds
Add new file to this folder and call it build-pipline.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
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-pipelines-tasks-terraform-installer.TerraformInstaller@0 displayName: 'Use Terraform 0.11.11' inputs: terraformVersion: 0.11.11 - task: DownloadSecureFile@1 displayName: 'Download secure file' inputs: secureFile: 'terraform.tfvars' - task: CopyFiles@2 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: DeleteFiles@1 displayName: 'Delete files from $(Build.SourcesDirectory)' inputs: SourceFolder: '$(Build.SourcesDirectory)' Contents: '**'
This is YAML code representation of this
And detailed explanation can you read here Using Terraform with Azure DevOps.
Save the code, commit and push your changes.
Go to Pipelines -> Builds
New build pipeline
Choose Use the visual designer
Choose your repo and branch
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.
Choose your YAML file. If you follow along the file should be under the builds folder
Click on OK
Now we click on Triggers to enable or disable continuous integration.
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
And Azure Portal
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