Managed Identity error while running Terraform plan

Hemanth Kumar 0 Reputation points
2025-01-16T09:20:28.18+00:00

Hi we have a terraform code that deploys Azure resources using SPN authentication. It successfully deployed as well. However we got a new requirement to use user assigned managed identity in our higher environments. We are following this article https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/guides/managed_service_identity.html#configuring-with-environment-variables and had set all the environment variables that are required in our Azure VM. We also assigned the managed identity with Contributor + User Access administrator role. Can you please check the below error and also in the snip and help us fix it

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

Terraform code for providers as below:

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
}

User's image

Not Monitored
Not Monitored
Tag not monitored by Microsoft.
42,922 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.