Terraform is unable to acquire access token from Azure CLI

Gagan Jassal 10 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

Community Center | Not monitored
{count} votes

1 answer

Sort by: Most helpful
  1. Gagan Jassal 10 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>

    2 people found this answer helpful.

Your answer

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