Terraform trying to install incorrect provider

Hi,

I’m using terraform 0.15.1 and am getting this error, but I don’t understand how terraform is thinking this should be happening.

$ terraform init
Initializing modules...
- network in modules/vm-template

Initializing the backend...

Initializing provider plugins...
- Finding latest version of telmate/proxmox...
- Finding latest version of hashicorp/proxmox...     <==== what is this?
- Installing telmate/proxmox v2.6.8...
- Installed telmate/proxmox v2.6.8 (self-signed, key ID A9EBBE091B35AFCE)

Partner and community providers are signed by their developers.
If you'd like to know more about provider signing, you can read about it here:
https://www.terraform.io/docs/cli/plugins/signing.html
╷
│ Error: Failed to query available provider packages
│ 
│ Could not retrieve the list of available versions for provider hashicorp/proxmox: provider registry registry.terraform.io does not have a provider named registry.terraform.io/hashicorp/proxmox
│ 
│ Did you intend to use telmate/proxmox? If so, you must specify that source address in each module which requires that provider. To see which modules are currently depending on hashicorp/proxmox, run the following
│ command:
│     terraform providers
╵
$ terraform providers

Providers required by configuration:
.
├── provider[registry.terraform.io/telmate/proxmox]
└── module.network
    └── provider[registry.terraform.io/hashicorp/proxmox]

My code looks like
main.tf

terraform {
  required_version = ">= 0.15"
  required_providers {
    proxmox = {
      source = "telmate/proxmox"
    }
  }
}

provider "proxmox" {
  pm_tls_insecure = true
  pm_api_url = "https://10.11.12.13:8006/api2/json"
  pm_user = "root@pam"
  pm_password = "vagrant"
}

module "network" {
  source         = "./modules/vm-template"
  vm_name = "whatever"
}

modules/vm-template/main.tf

variable "vm_name" {
  type = string
}

resource "proxmox_vm_qemu" "template" {
  count       = 1
  name        = var.vm_name
  target_node = "pve1"
  clone       = "template"
  full_clone  = "true"
  os_type     = "cloud-init"

  lifecycle {
    ignore_changes = [
      network,
      target_node,
    ]
  }
}

Per the initial error message, I specify the terraform provider in my module which doesn’t end up working.
main.tf

terraform {
  required_version = ">= 0.15"
  required_providers {
    proxmox = {
      source = "telmate/proxmox"
    }
  }
}

provider "proxmox" {
  pm_tls_insecure = true
  pm_api_url = "https://10.11.12.13:8006/api2/json"
  pm_user = "root@pam"
  pm_password = "vagrant"
  alias = "pm"
}

module "network" {
  source         = "./modules/vm-template"
  vm_name = "whatever"
  providers = {
    proxmox = proxmox.pm
  }
}
$ terraform  init
Initializing modules...
There are some problems with the configuration, described below.

The Terraform configuration must be valid before initialization so that
Terraform can determine which modules and providers need to be installed.
╷
│ Warning: Provider proxmox is undefined
│ 
│   on main.tf line 74, in module "network":
│   74:     proxmox = proxmox.pm
│ 
│ Module module.network does not declare a provider named proxmox.
│ If you wish to specify a provider configuration for the module, add an entry for proxmox in the required_providers block within the module.
╵

╷
│ Error: Invalid type for provider module.network.provider["registry.terraform.io/hashicorp/proxmox"]
│ 
│   on main.tf line 74, in module "network":
│   74:     proxmox = proxmox.pm
│ 
│ Cannot use configuration from provider["registry.terraform.io/telmate/proxmox"].pm for module.network.provider["registry.terraform.io/hashicorp/proxmox"]. The given provider configuration is for a different provider
│ type.
╵

Hi @pgporada,

The intent of the first error message you saw is to direct you to specify that your child module requires this provider, by adding a block like this to one of the files in the ./modules/vm-template directory:

terraform {
  required_providers {
    proxmox = {
      source = "telmate/proxmox"
    }
  }
}

This statement will tell Terraform that when you say proxmox in that module you mean telmate/proxmox rather than hashicorp/proxmox, and thus the two modules (your root module and this one) will then agree about which proxmox provider they both depend on.

1 Like

Aha, that’s new to me and I didn’t understand it from the error or documentation. Thank you!

Edit: Re-reading the error message again the 100th time it does make sense now.