Terraform 应用导致从 Azure CLI 填充客户端 ID 时出错

Pio*_*ski 9 terraform terraform-provider-azure

我尝试应用 terraform plan 与terraform apply. 但是当我运行命令时出现以下错误

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`.
Run Code Online (Sandbox Code Playgroud)

我确实安装了 Azure CLI,并且使用az login. 当我运行时,az login我会被重定向到登录页面,在那里我可以正常登录。

terraform init可以毫无问题地工作。

在我的地形文件下面:

provider "azurerm" {
  version = "1.38.0"
}
Run Code Online (Sandbox Code Playgroud)

我还尝试提供订阅和租户 ID,但没有帮助:

provider "azurerm" {
  version = "1.38.0"

  subscription_id = "00000000-0000-0000-0000-000000000000"
  tenant_id       = "00000000-0000-0000-0000-000000000001"
}
Run Code Online (Sandbox Code Playgroud)

Ans*_*-MT 18

错误:构建 AzureRM 客户端时出错:从 Azure CLI 填充客户端 ID 时出错:未找到授权令牌 - 请确保安装了 Azure CLI,然后使用 登录az login

错误是由于您使用的 Azure CLI 版本造成的Azure CLI 版本中2.30.0发生了重大更改,Azure 将身份验证ADALMSAL. 如果您使用最新的 Azure CLI 和旧的 Terraform azurerm,则身份验证将失败,从而导致错误

解决此问题,您必须使用最新的 Azure CLI 版本 ie2.32.0,同时尝试使用 terraform 最新的azurermProvider ie2.92.0

升级 CLI 版本,您可以运行az upgrade命令,在terraform 中您可以使用以下命令:

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

provider "azurerm" {
  # Configuration options
}
Run Code Online (Sandbox Code Playgroud)

您可以参考这些类似的 Github 问题Issue 1以及Issue 2