Terraform -AZ CLI- MSAL令牌错误 - 不存在用户

发布于 2025-02-06 22:18:51 字数 1175 浏览 4 评论 0原文

自从今天以来,我会使用Azure AD身份验证遇到有关Terraform启动的错误。

Terrform v1.2.2
AZ CLI v2.37.0

terraform {
  required_providers {
    azurerm = {
      source  = "hashicorp/azurerm"
      version = "~>3.0"
    }
  }
  backend "azurerm" {
    tenant_id            = "XXX"
    subscription_id      = "XXX"
    resource_group_name  = "XXX"
    storage_account_name = "XXX"
    container_name       = "tfstate"
    key                  = "devops.terraform.tfstate"
    use_azuread_auth     = true
  }
}
terraform init
> Error: obtaining Authorization Token from the Azure CLI: parsing json result from the Azure CLI: waiting for the Azure CLI: exit status 1: ERROR: User 'XXX' does not exist in MSAL token cache. Run `az login`.

运行AZ登录az注销/AZ登录,错误仍然存​​在。 删除MSAL令牌缓存文件或AZ帐户清除也无济于事。 我正在使用最新版本的Terraform和AZ CLI。在遇到错误之前,我在使用Terraform v1.1.x,但升级也无法解决。 另外,用户在account.username中明确存在于msal_token_cache.json中。

有什么建议吗?

干杯, AJ

解决:
重新安装AZ CLI后,问题解决了。我认为这是WSL2的问题。如果不是Terraform和AZ CLI都是Windows二进制文件(或两个Linux二进制文件),则可能遍布整个配置。 反正谢谢!

since today I am experiencing an error concerning terraform initilization using Azure AD Authentication.

Terrform v1.2.2
Az Cli v2.37.0

terraform {
  required_providers {
    azurerm = {
      source  = "hashicorp/azurerm"
      version = "~>3.0"
    }
  }
  backend "azurerm" {
    tenant_id            = "XXX"
    subscription_id      = "XXX"
    resource_group_name  = "XXX"
    storage_account_name = "XXX"
    container_name       = "tfstate"
    key                  = "devops.terraform.tfstate"
    use_azuread_auth     = true
  }
}
terraform init
> Error: obtaining Authorization Token from the Azure CLI: parsing json result from the Azure CLI: waiting for the Azure CLI: exit status 1: ERROR: User 'XXX' does not exist in MSAL token cache. Run `az login`.

Upon running az login or az logout/az login, the error remains.
Deleting MSAL token cache file or az account clear do not help, either.
I am using latest versions of terraform and az cli. I was using terraform v1.1.x before when I encountered the error but upgrading did not solve it, either.
Also, the user definetly exists in the msal_token_cache.json at Account.username.

Any suggestions?

Cheers,
AJ

SOLVED:
After reinstalling az cli, the issue resolved. I think it is a problem with WSL2. If not both terraform and az cli are windows binaries (or both linux binaries), configuration is probably all over the place.
Thanks anyway!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

小耗子 2025-02-13 22:18:52

我遇到了同样的问题。我做了以下操作,并解决了问题:

AZ帐户清除了

AZ登录命令。

I was experiencing the same issue. I did the following and the issue was resolved:

az account clear

The ran the az login command.

全部不再 2025-02-13 22:18:52

如果有人在az登录

我通过运行以下命令

az登录解决了我的问题 - 租户ID

id ID 在Azure门户上找到的ID/GUID。

请按照以下步骤获取房客ID:

登录到Azure门户。
在Azure服务标题下,选择Microsoft Entra ID。
在概述屏幕中,您可以复制房客ID

If anyone is struggling with az login

I solved my problem by running the following command

az login --tenant id

replace id with the id/guid found on azure portal.

follow these steps to get the tenant id:

Sign in to the Azure portal.
Under the Azure services heading, select Microsoft Entra ID.
In the overview screen you can copy the tenant id

煮酒 2025-02-13 22:18:52

谢谢 ajqrea 共享解决方案。将其作为解决方案发布,以帮助其他社区成员将来可能会遇到同样的问题。

错误是由于您更改了Azure帐户的密码,并且存储在磁盘上的访问令牌变得无效。

Terraform在内部只是调用 az帐户获取访问 - 因此,您应该能够运行相同的命令以查看错误。

解决方案:重新安装或升级azure-cli-iot-ext扩展程序后,Terraform能够通过新的更新密码再次检索访问令牌。

参考: https://github.com/hashiCorp.com/hashasicorp/hashicorp/terraform-profider-profider-provider- -azurerm/essugy/3686

Thank You AJQREA sharing the solution. Posting it as an solution to help other community member who might encounter the same problem in future.

The error is due to you having changed the password of your Azure account and the access token stored on the disk becoming invalid.

Terraform internally is just calling az account get-access-token - as such you should be able to run the same command to see the error.

Solution : After reinstalling or upgrading the azure-cli-iot-ext extension, Terraform was able to retrieve the access token again with new updated password.

Reference : https://github.com/hashicorp/terraform-provider-azurerm/issues/3686

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文