Unable to Authenticate to Azure launched via playground session from Terraform

Hi @kodekloud-support3

Followed below sequence,

Step1: Launched Azure Playground, logged in to Azure portal.
Step 2: From CLI, did “az login” which redirected to a browser, there authenticated to azure playground session in the browser.
Step 3: From CLI, ran below and got the “subscription id” - “b2aec48f-6dad-4d57-ad25-dad521fe74a4”
“az account list”
[
{
“cloudName”: “AzureCloud”,
“homeTenantId”: “0d7cc8e9-be54-45cc-b2e3-041a9b45aa57”,
“id”: “b2aec48f-6dad-4d57-ad25-dad521fe74a4”,
“isDefault”: true,
“managedByTenants”: [],
“name”: “KodeKloud Azure Production Labs”,
“state”: “Enabled”,
“tenantId”: “0d7cc8e9-be54-45cc-b2e3-041a9b45aa57”,
“user”: {
“name”: “[email protected]”,
“type”: “user”
}
}
]
Step 4: From CI, az account set --subscription=“b2aec48f-6dad-4d57-ad25-dad521fe74a4”

Step 5: On the Terraform configuration file, entered the following block, (hard coded “location” & “resource_group_name” values)

Configure the Microsoft Azure Provider

provider “azurerm” {
features {}
subscription_id = “b2aec48f-6dad-4d57-ad25-dad521fe74a4”
}

Create VC

resource “azurerm_virtual_network” “example” {
name = “example-network”
address_space = [“10.0.0.0/16”]
location = “East US”
resource_group_name = “ODL-azure-723388”
}

Step 6: When ran, “terraform plan” after “terraform init”, getting below error as doesn’t have permission to use Resource Manager API,


│ 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: resources.ProvidersClient#List: Failure sending request: StatusCode=0 – Original Error: context canceled

│ with provider[“Terraform Registry”],
│ on main.tf line 11, in provider “azurerm”:
│ 11: provider “azurerm” {

Any help would be appreciated. :blush:

Ref: Azure Provider: Authenticating via the Azure CLI | Guides | hashicorp/azurerm | Terraform Registry