I’m learning Terraform and trying to organize the code in modules. The code uses two providers, aws
and hetznercloud/hcloud
. The first one works alright, but the hcloud
declaration is not inherited in the module. This is how they are declared in main.tf
:
provider "hcloud" {
token = var.hcloud_token
}
provider "aws" {
region = "eu-west-2"
}
When I run terraform init
, though, Terraform tries to use hashicorp/hcloud
instead of hetznercloud/hcloud
and fails:
Initializing provider plugins...
- Finding latest version of hashicorp/hcloud...
- Reusing previous version of hetznercloud/hcloud from the dependency lock file
- Reusing previous version of hashicorp/aws from the dependency lock file
- Using previously-installed hetznercloud/hcloud v1.26.2
- Using previously-installed hashicorp/aws v3.45.0
╷
│ Error: Failed to query available provider packages
│
│ Could not retrieve the list of available versions for provider hashicorp/hcloud: provider registry registry.terraform.io does not have a provider named
│ registry.terraform.io/hashicorp/hcloud
│
│ Did you intend to use hetznercloud/hcloud? If so, you must specify that source address in each module which requires that provider. To see which modules
│ are currently depending on hashicorp/hcloud, run the following command:
│ terraform providers
Here’s the output of terraform providers
:
Providers required by configuration:
.
├── provider[registry.terraform.io/hetznercloud/hcloud]
├── provider[registry.terraform.io/hashicorp/aws]
└── module.mod_zookeeper
├── provider[registry.terraform.io/hashicorp/hcloud]
└── provider[registry.terraform.io/hashicorp/aws]
I tried to redefine the providers in the module code, but then I get this message:
│ Error: Module module.mod_zookeeper contains provider configuration
│
│ Providers cannot be configured within modules using count, for_each or depends_on.
If I remove resources using Hetzner cloud from the module, the remaining aws
providers works alright.
What’s wrong with hcloud
?