1

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

Allan Xu
  • 7,998
  • 11
  • 51
  • 122
  • 1
    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 Nov 04 '20 at 06:31
  • Terraform thinks you are trying to install a provider called `custom`. Can you edit your question to include an [mcve] that reproduces that error please? – ydaetskcoR Nov 04 '20 at 13:40
  • 1
    This is a common error, see https://stackoverflow.com/a/64556421/3665058 for a potential review of your code. – Christian Pearce Nov 04 '20 at 13:43
  • 1
    @ChristianPearce, you are correct. It was a syntax issue. Thank you! – Allan Xu Nov 04 '20 at 18:00
  • Does this answer your question? [Using Terraform to import existing resources on Azure](https://stackoverflow.com/questions/47439848/using-terraform-to-import-existing-resources-on-azure) – Charles Xu Nov 05 '20 at 02:34
  • @CharlesXu, no. With ChristianPearce hint, I learned that some syntax error cause this error. Quite misleading. – Allan Xu Nov 05 '20 at 02:41
  • So do you solve the problem? If yes, add your answer. If no, please give the updates for what you want. And give all the Terraform script you use. – Charles Xu Nov 05 '20 at 02:43
  • @CharlesXu, below shows the cause of the error form me. – Allan Xu Nov 05 '20 at 17:44

2 Answers2

1

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" {

Allan Xu
  • 7,998
  • 11
  • 51
  • 122
1

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"
    }
  }
}
tkonsta
  • 191
  • 1
  • 5