title | description | keywords | ms.topic | ms.date | ms.custom |
---|---|---|---|---|---|
Authenticate Terraform to Azure |
Learn the various options to authenticate to Azure with a Microsoft Account |
azure devops terraform cli powershell authentication microsoft account subscription environment variables provider block |
how-to |
08/29/2021 |
devx-track-terraform |
[!INCLUDE Terraform abstract]
To use Terraform commands against your Azure subscription, you must first authenticate Terraform to that subscription. This article covers some common scenarios for authenticating to Azure.
In this article, you learn how to:
[!div class="checklist"]
- 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
[!INCLUDE open-source-devops-prereqs-azure-subscription.md]
[!INCLUDE configure-terraform.md]
[!INCLUDE authenticate-to-azure.md]
Verify that you've authenticated to the Azure subscription by displaying the current subscription.
To confirm the current Azure subscription via the Azure CLI, run az account show.
az account show
To confirm the current Azure subscription via Azure PowerShell, run Get-AzContext.
Get-AzContext
[!div class="nextstepaction"] Create an Azure resource group