Install Terraform on Windows with Bash

Terraform enables the definition, preview, and deployment of cloud infrastructure. Using Terraform, you create configuration files using HCL syntax. The HCL syntax allows you to specify the cloud provider - such as Azure - and the elements that make up your cloud infrastructure. After you create your configuration files, you create an execution plan that allows you to preview your infrastructure changes before they're deployed. Once you verify the changes, you apply the execution plan to deploy the infrastructure.

This article presents you with the options to authenticate to Azure for use with Terraform.

In this article, you learn how to:

  • Install the Git Bash terminal emulator
  • Install Azure CLI
  • Install Terraform
  • Configure your environment to run Terraform on Windows
  • Understand common Terraform and Azure authentication scenarios
  • Authenticate via a Microsoft account from Cloud Shell (using Bash or PowerShell)
  • Authenticate via a Microsoft account from Windows (using Bash or PowerShell)
  • Create a service principal using the Azure CLI
  • Create a service principal using Azure PowerShell
  • Specify service principal credentials in environment variables
  • Specify service principal credentials in a Terraform provider block

1. Configure your environment

  • Azure subscription: If you don't have an Azure subscription, create a free account before you begin.

2. Install a terminal emulator

There are many options on Windows to run bash commands, including Git Bash and Windows Terminal. This article has been tested using Git Bash. Download and install Git Bash.

3. Install the Azure CLI

Install the Azure CLI. This article was tested using Azure CLI version 2.26.1.

4. Install Terraform for Windows

  1. Download Terraform. This article was tested using Terraform version 1.1.4.

  2. From the download, extract the executable to a directory of your choosing (for example, c:\terraform).

  3. Update your system's global PATH environment variable to include the directory that contains the executable.

  4. Open a terminal window.

  5. Verify the global path configuration with the terraform command.

    terraform -version
    

Troubleshoot Terraform on Azure

Troubleshoot common problems when using Terraform on Azure

Next steps