0
votes

I assume I am using the latest version of azurerm:

provider "azurerm" {
  version = "=2.34.0"
  features {}
}

As soon as I add this resource to my tf script:

https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/policy_assignment

I get this error when I do terraform init:

>terraform init

Initializing the backend...

Initializing provider plugins...
- Finding latest version of hashicorp/custom...
- Finding hashicorp/azurerm versions matching "2.34.0"...
- Installing hashicorp/azurerm v2.34.0...
- Installed hashicorp/azurerm v2.34.0 (signed by HashiCorp)

Error: Failed to install provider

Error while installing hashicorp/custom: provider registry
registry.terraform.io does not have a provider named
registry.terraform.io/hashicorp/custom

Am I missing any custom terraform provider? Looking at the Terraform documentation in the link above, I expect the azurerm_policy_definition resource must be included n the azurerm

2
What do you mean" I expect the azurerm_policy_definition resource must be included n the azurerm"?Are you using the latest terraform version Terraform v0.13.5? Could you show your full code?Nancy Xiong
Terraform thinks you are trying to install a provider called custom. Can you edit your question to include an minimal reproducible example that reproduces that error please?ydaetskcoR
This is a common error, see stackoverflow.com/a/64556421/3665058 for a potential review of your code.Christian Pearce
@ChristianPearce, you are correct. It was a syntax issue. Thank you!Allan Xu

2 Answers

1
votes

Thanks to @ChristianPearce who deserves the credit for the answer.

This is a common and potentially misleading error.

There could me many scripting issues that cause this error.

In my case my resource name had typo in it like below:

resource "azurerm_virtual_network_typo_in_type" "main" {

1
votes

This could also be a problem with terraform sub-modules as discussed in https://github.com/hashicorp/terraform/issues/25602.

For community providers, every module requires a required_providers block with an entry specifying the provider source.

So basically you need to have this in all your modules and in your main tf-script (replace the custom-prov-name by you actual provider):

terraform {
  required_providers {
    custom-prov-name = {
      source = ".../custom-prov-name"
    }
  }
}