Azure DevOps | Using Terraform

Using Terraform with Azure DevOps

Azure DevOps is a set of development tools and services for software development, while Terraform is a popular infrastructure as code (IaC) tool used to provision and manage cloud resources. Combining the power of Terraform with Azure DevOps can help automate infrastructure deployment and management in your projects.

In this guide, we’ll walk through the steps to set up and integrate Terraform with Azure DevOps.


  1. Azure DevOps Account: You need an Azure DevOps account to get started. Sign up if you don’t have one.

  2. Azure Subscription: Access to an Azure subscription to create and manage Azure resources.

  3. Terraform: Install Terraform on your local machine.

  4. Azure CLI: Install the Azure CLI.


1. Create a New Azure DevOps Project

  1. Log in to your Azure DevOps account.

  2. Create a new project or select an existing one for your Terraform infrastructure.

2. Set Up a Git Repository

  1. Create a Git repository within your Azure DevOps project to store your Terraform code.

  2. Clone the repository to your local machine.

3. Terraform Configuration

  1. Create a directory for your Terraform configurations within your Git repository.

  2. Write your Terraform code for provisioning Azure resources in this directory.

  3. Initialize your Terraform configuration:

    terraform init
  4. Create a file and define your Azure resources using the Azure Terraform Provider.

  5. Use environment variables or other methods to securely store your Azure credentials and sensitive information.

4. Create an Azure DevOps Pipeline

  1. In your Azure DevOps project, go to Pipelines and create a new pipeline.

  2. Select the Git repository where your Terraform code is stored.

  3. Choose a pipeline template based on your project’s needs. You can also create a YAML pipeline.

  4. Configure the pipeline to execute Terraform commands (e.g., terraform init, terraform plan, and terraform apply) as tasks.

5. Securely Store Secrets

  1. Use Azure DevOps Variable Groups or Azure Key Vault to securely manage and store secrets, such as Azure service principal credentials.

6. Trigger the Pipeline

  1. Commit your Terraform code to the Git repository.

  2. Manually trigger the Azure DevOps pipeline or set up automatic triggers, such as on code commits or pull requests.

7. Monitor and Manage

  1. Monitor the pipeline’s progress and logs through the Azure DevOps interface.

  2. Leverage Azure DevOps features like approval gates and release environments for more advanced control and automation.

8. Cleanup

  1. After you’re done with your resources, add Terraform code to destroy or deprovision them.

  2. Run terraform destroy in your Azure DevOps pipeline when you’re ready to clean up your Azure resources.

By following these steps, you can set up a seamless integration between Terraform and Azure DevOps, automating your infrastructure provisioning and management processes.

What Next?

Using Terraform in conjunction with Azure DevOps can significantly enhance your infrastructure provisioning and management workflow. It allows for automation, version control, and collaboration, making your infrastructure as code projects more efficient and reliable.

This post is licensed under CC BY 4.0 by the author.