Search code examples
terraform

401 ClaimsChallengeRequiredException when reading azuread_groups with azuread terraform provider


I am using the azuread terraform provider to read Entra ID groups as a data object. The code hasn't changed but it has stopped working:

terraform {
  required_providers {
    azuread = {
      source  = "hashicorp/azuread"
      version = "~> 2.53.1"
    }
  }
}

data "azuread_groups" "groups" {
  display_name_prefix = "asdf-"
}

After running az login and terraform plan I am getting the following error:

│ Error: No groups found with display name prefix: "asdf-"
│
│   with data.azuread_groups.groups,
│   on asdf.tf line 5, in data "azuread_groups" "groups":
│    100:   display_name_prefix = "asdf-"
│
│ GroupsClient.BaseClient.Get(): unexpected status 401 with OData error: InvalidAuthenticationToken: Exception of type
│ 'Microsoft.Graph.AGS.Contracts.ClaimsChallengeRequiredException' was thrown.

This error just started happening without any code changes.

I have tried deleting the .azure directory, but the error persists.


Solution

  • To fix this issue, run the following command:

    az account clear
    

    https://learn.microsoft.com/en-us/cli/azure/account?view=azure-cli-latest#az-account-clear