8

I try to apply terraform plan with terraform apply. But when I run the command I get the following error

Error: Error building AzureRM Client: Error populating Client ID from the Azure CLI: 
No Authorization Tokens were found - 
please ensure the Azure CLI is installed and then log-in with `az login`.

I do have the Azure CLI installed and I'm logged in with az login. When I run az login I am redirected to the landing page where I am able to log in just fine.

Also terraform init works without any problems.

Below my terraform file:

provider "azurerm" {
  version = "1.38.0"
}

I also tried to provide subscription and tenant IDs but it didn't help:

provider "azurerm" {
  version = "1.38.0"

  subscription_id = "00000000-0000-0000-0000-000000000000"
  tenant_id       = "00000000-0000-0000-0000-000000000001"
}
PiotrWolkowski
  • 8,408
  • 6
  • 48
  • 68
  • That provider version is deprecated, and could easily be incompatible with any recent version of the CLI. Try updating to `~> 2.0` and see how that goes. – Matthew Schuchard Jan 16 '22 at 19:01

1 Answers1

18

Error: Error building AzureRM Client: Error populating Client ID from the Azure CLI: No Authorization Tokens were found - please ensure the Azure CLI is installed and then log-in with az login.

This error is due to the Azure CLI version that you are using . There was a breaking change in the Azure CLI version 2.30.0 where Azure migrated the authentication from ADAL to MSAL. For which if you are using Azure CLI latest and Terraform azurerm old then , it will fail in authentication which will result in the error.

To Fix the problem you will have to use the latest Azure CLI version i.e. 2.32.0 and also at the same time try to use the terraform latest azurerm Provider i.e. 2.92.0.

To Upgrade CLI version , You can run az upgrade command and in terraform you can use the below :

terraform {
  required_providers {
    azurerm = {
      source = "hashicorp/azurerm"
      version = "2.92.0"
    }
  }
}

provider "azurerm" {
  # Configuration options
}

You can refer these Similar Github Issues are well : Issue 1 and Issue 2

Ansuman Bal
  • 9,705
  • 2
  • 10
  • 27