Terraform is unable to acquire access token from Azure CLI

GJassal 5 Reputation points
2024-11-21T14:13:16.42+00:00

In my local windows pc I have Azure CLI and Terraform.

I am logged into Azure CLI.

az account show shows my logged in user as isDefault = true

I am able to connect with Azure resources, no hickups.

I run terraform plan it throws me this error:

Error: building account: could not acquire access token to parse claims: running Azure CLI: exit status 1: ERROR: Account has previously been signed out of this application.. Status: Response_Status.Status_AccountUnusable, Error code: 0, Tag: 540940121

Screenshot 2024-11-21 090333

I ran az account get-access-token and token is there and valid

Screenshot 2024-11-21 090117

I ran az ad signed-in-user show it doesn't shows the currently logged in user

Screenshot 2024-11-21 090401

The above issues are only in my local Windows 11 PC at home.

It's not a company laptop. Not domain joined. No network restrictions.

I have tried:

  • az clear; az login; az login --tenant; az login --scope;
  • uninstalling and installing Azure CLI
  • deleting .azure folder
  • deleting

Will appreciate your support as it's stopping me to use VS Code to work with Terraform.

Thanks,

Gagan

Not Monitored
Not Monitored
Tag not monitored by Microsoft.
40,234 questions
{count} votes

1 answer

Sort by: Most helpful
  1. GJassal 5 Reputation points
    2024-11-23T20:03:14.0533333+00:00

    I was able to resolve this issue by following this trick from this https://developercommunity.visualstudio.com/t/WAM-error:-Account-has-previously-been/10700816#T-N10735701

    Delete all the files under this folder. C:\Users<username>\AppData\Local\Microsoft\IdentityCache

    I still need to sign in to Azure CLI by specifying the --tenant explicitly: az login --tenant <tenant_id>

    1 person found this answer helpful.

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.