Managed Identity error while running Terraform plan
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
}