Managed Identity Authentication error while running Terraform Plan

Hemanth Kumar 0 Reputation points
2025-01-16T09:09:57.44+00:00

We are deploying our Infrastructure in Azure using Terraform. With SPN authentication, we were able to execute the terraform script and deploy the resources successfully. However as our requirement changed in the production environment, we are trying to use a "User assigned managed identity" instead of SPN for Terraform authentication to Azure. We followed this document https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/guides/managed_service_identity.html#configuring-terraform-to-use-a-managed-identity

  1. We created a User MI and assigned with Contributor + User Access administrator role at the subscription level
  2. We passed all attributes like Client ID, tenant ID and subscription ID in an Azure VM environment variables as mentioned in the above document.
  3. We tried to run the Terraform plan and got the below error. I can guarantee that this is not a terraform error. We might be missing something at Azure end. Please check the error below.

ManagedIdentityAuthorizer: failed to request token from metadata endpoint: received HTTP status 400 with error: {"error":"invalid_request","error_description":"Identity not found"}

User's image

Tf providers used.

provider "azurerm" {
  storage_use_azuread = true
  use_cli             = true
  features {}
  subscription_id = var.subscription_id
  use_msi         = true
}


provider "azurerm" {
  alias = "DNS"
  features {}
  subscription_id = var.dns_subscription_id
  use_msi = true
}

Can you please check the above error and assist us to be able to fix it?

Microsoft Identity Manager
Microsoft Identity Manager
A family of Microsoft products that manage a user's digital identity using identity synchronization, certificate management, and user provisioning.
743 questions
Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
23,027 questions
{count} votes

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.