I'm confronting an error related to Managed Identity. I want to provision virtual machines using Terraform in Azure. Here is my code block:
terraform {
# Use a recent version of Terraform
required_version = ">= 0.13"
# Map providers to thier sources, required in Terraform 13+
required_providers {
# Azure Resource Manager 2.x
azurerm = {
source = "hashicorp/azurerm"
version = "~> 2.0"
}
}
}
provider "azurerm" {
features {}
use_msi = true
// subscription_id = "XXXXXXXXX-4663-4c2e-XXXX-XXXXXXXXX"
// tenant_id = "XXXXXXXXX-232r-3w2e-XXXX-XXXXXXXXX"
}
I've tried with both enabling use_msi = true
and later with tenant_id along with subscription_id
It prompts me a following error:
Unable to list provider registration status, it is possible that this is due to invalid credentials or the service principal does not have permission to use the Resource Manager API, Azure error: azure.BearerAuthorizer#WithAuthorization: Failed to refresh the Token for request to https://management.azure.com/subscriptions//providers?api-version=2016-02-01: StatusCode=0 -- Original Error: the MSI endpoint is not available. Failed HTTP request to MSI endpoint: Get "http://177.xxx.232.324/metadata/identity/oauth2/token?api-version=2018-02-01": dial tcp 177.xxx.232.324:80: connectex: A socket operation was attempted to an unreachable network.
NOTE I've already set subscription with
az account set --subscription="XXXXXXXXXXXXXXXXXX"
however no success.
What should i keep in my code base or what is the right approach?