Not able to create resource via HCL

Hi Community,

I am new in Terraform and i have started learning this .

I am getting the below error

Planning failed. Terraform encountered an error while generating this plan.


╷

│ Error: Error ensuring Resource Providers are registered.

│

│ Terraform automatically attempts to register the Resource Providers it supports to

│ ensure it's able to provision resources.

│

│ If you don't have permission to register Resource Providers you may wish to use the

│ "skip_provider_registration" flag in the Provider block to disable this functionality.

│

│ Please note that if you opt out of Resource Provider Registration and Terraform tries

│ to provision a resource from a Resource Provider which is unregistered, then the errors

│ may appear misleading - for example:

│

│ > API version 2019-XX-XX was not found for Microsoft.Foo

│

│ Could indicate either that the Resource Provider "Microsoft.Foo" requires registration,

│ but this could also indicate that this Azure Region doesn't support this API version.

│

│ More information on the "skip_provider_registration" flag can be found here:

│ https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs#skip_provider_registration

│

│ Original Error: Cannot register providers: Microsoft.MachineLearningServices, Microsoft.OperationalInsights, Microsoft.ManagedIdentity, Microsoft.DBforMariaDB, Microsoft.HealthcareApis, Microsoft.ServiceBus. Errors were: Cannot register provider Microsoft.MachineLearningServices with Azure Resource Manager: Post "https://management.azure.com/subscriptions/1d902123-bc1c-4dcc-9779-6f6995d97b72/providers/Microsoft.MachineLearningServices/register?api-version=2022-09-01": HTTP response was nil; connection may have been reset.

│ Cannot register provider Microsoft.OperationalInsights with Azure Resource Manager: Post "https://management.azure.com/subscriptions/1d902123-bc1c-4dcc-9779-6f6995d97b72/providers/Microsoft.OperationalInsights/register?api-version=2022-09-01": HTTP response was nil; connection may have been reset.

│ Cannot register provider Microsoft.ManagedIdentity with Azure Resource Manager: Post "https://management.azure.com/subscriptions/1d902123-bc1c-4dcc-9779-6f6995d97b72/providers/Microsoft.ManagedIdentity/register?api-version=2022-09-01": HTTP response was nil; connection may have been reset.

│ Cannot register provider Microsoft.DBforMariaDB with Azure Resource Manager: Post "https://management.azure.com/subscriptions/1d902123-bc1c-4dcc-9779-6f6995d97b72/providers/Microsoft.DBforMariaDB/register?api-version=2022-09-01": HTTP response was nil; connection may have been reset.

│ Cannot register provider Microsoft.HealthcareApis with Azure Resource Manager: Post "https://management.azure.com/subscriptions/1d902123-bc1c-4dcc-9779-6f6995d97b72/providers/Microsoft.HealthcareApis/register?api-version=2022-09-01": HTTP response was nil; connection may have been reset.

│ Cannot register provider Microsoft.ServiceBus with Azure Resource Manager: Post "https://management.azure.com/subscriptions/1d902123-bc1c-4dcc-9779-6f6995d97b72/providers/Microsoft.ServiceBus/register?api-version=2022-09-01": HTTP response was nil; connection may have been reset.

│

│   with provider["registry.terraform.io/hashicorp/azurerm"],

│   on main.tf line 10, in provider "azurerm":

│   10: provider "azurerm" {

│

main.tf

 terraform {   required_providers {     azurerm = {       source = "hashicorp/azurerm"       version = "3.104.2"     }   } } provider "azurerm" {   subscription_id = "xxxxxxxxxxxxxxxxx"   tenant_id = "xxxxxxxxxxxxxxxxx"   client_id = "xxxxxxxxxxxxxxxxx"   client_secret = "xxxxxxxxxxxxxxxxx"   features {} } resource "azurerm_resource_group" "appgrp" {   name     = "app-grp"   location = "Central India" }

Hi @aniketpant1,

This is a question related to the Azure Provider so would usually be better posted in that area. However I can help clear this up for you.

As the error states:

Terraform automatically attempts to register the Resource Providers it supports to ensure it’s able to provision resources.

Terraform will attempt to do this under the user context it is running and if that user does not have the appropriate permissions to register providers then you will see the above error. This can be worked around, as stated in the error:

If you don’t have permission to register Resource Providers you may wish to use the “skip_provider_registration” flag in the Provider block to disable this functionality.

The details on how to use/add this flag can be found here: skip_provider_registration | hashicorp/azurerm | Terraform | Terraform Registry

See this page for more information on what ,generally, Azure resource providers are, and their management, and permissions required to register them: Resource providers and resource types - Azure Resource Manager | Microsoft Learn

HTH

Happy Terraforming