Managed Identity Authentication error while running Terraform Plan
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
- We created a User MI and assigned with Contributor + User Access administrator role at the subscription level
- We passed all attributes like Client ID, tenant ID and subscription ID in an Azure VM environment variables as mentioned in the above document.
- 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"}
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?