Azure DevOps CI
Azure DevOps CI
Terraform is an Infrastructure-as-Code (IAC) tool that enables users to define and deploy infrastructure
resources like computing, storage, and networking using simple, human-readable configuration files.
How Terraform Works?
Terraform manages cloud resources and services via APIs.
main.tf: This is the main configuration file where we define our resources.
backend.tf: Specifies the path where Terraform stores its state data files for the current
infrastructure. Terraform keeps track of the managed resources. This state can be
stored locally or remotely(remote backend).
The State File: contains full details of resources in our terraform code. When you
modify and apply something to your code to the cloud, Terraform will look into the state
file and compare the changes made in the code from that state file and the changes to
the infrastructure based on the state file.
When you run the Terraform apply command to create an infrastructure on the cloud,
Terraform creates a state file called “terraform.tfstate.”
version.tf: Terraform will check the version of the installed Terraform binary that
executes the Terraform configuration.
Terraform core → Core is responsible for the life cycle management of infrastructure.
We will be using the Azure DevOps build pipeline for terraform pre-requisites and planning, and the
Azure DevOps Release pipeline to run the terraform apply for resource provisioning into multiple Azure
environments.
- task: TerraformTaskV4@4
displayName: Tf plan
inputs:
provider: 'azurerm'
command: 'plan'
commandOptions: '-out $(Build.SourcesDirectory)/tfplanfile'
environmentServiceNameAzureRM: '${SERVICECONNECTION}'
- task: ArchiveFiles@2
displayName: Archive files
inputs:
rootFolderOrFile: '$(Build.SourcesDirectory)/'
includeRootFolder: false
archiveType: 'zip'
archiveFile: '$(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip'
replaceExistingArchive: true
- task: PublishBuildArtifacts@1
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)'
ArtifactName: '$(Build.BuildId)-build'
publishLocation: 'Container'
Release Pipeline
We will also add a destroy stage to destroy the resources once our demo is completed with a pre-
deployment approval step.