Introduction
When starting development with HCP Terraform, using Hashicorp providers often doesn't require any initial configuration. The first part of the resource name is the provider's name and hashicorp/
is assumed as a default path when downloading during terraform init.
When a 3rd-party provider is used in the same situation, such an assumption is invalid as those providers are stored at a different path. As the path is incorrect, the user will see the following error message: Error: Failed to query available provider packages
At the first glance, this small difference might be hard to spot. Here is an example for datadog, but it applies to all not in hashicorp/
path.
$ terraform init
...
│ Error: Failed to query available provider packages
│
│ Could not retrieve the list of available versions for provider
│ hashicorp/datadog: provider registry registry.terraform.io does not have a
│ provider named registry.terraform.io/hashicorp/datadog
...
Please note the hashicorp/datadog being used instead of correct datadog/datadog in the error message. Public registry clearly states "datadog":
https://registry.terraform.io/providers/DataDog/datadog/latest/docs
Cause
When provider configuration does not exist, HCP Terraform strips the first part of the resource name and tries hashicorp/
as path to download the provider.
Solution:
The solution is fairly simple. The configuration should be included for any 3rd-party provider. In our example case, an example can be found on the following page:
https://registry.terraform.io/providers/DataDog/datadog/latest/docs
It lists the source for the provider named datadog, overriding the default path:
$ cat provider.tf
terraform {
required_providers {
datadog = {
source = "DataDog/datadog"
}
}
}
Outcome
With the configuration in place, the init command succeeds:
$ terraform init
Initializing the backend...
Initializing modules...
Initializing provider plugins...
- Reusing previous version of datadog/datadog from the dependency lock file
- Using previously-installed datadog/datadog v3.42.0
Terraform has been successfully initialized!
You may now begin working with Terraform. Try running "terraform plan" to see
any changes that are required for your infrastructure. All Terraform commands
should now work.
If you ever set or change modules or backend configuration for Terraform,
rerun this command to reinitialize your working directory. If you forget, other
commands will detect it and remind you to do so if necessary.
Additional Information
-
https://developer.hashicorp.com/terraform/language/providers/configuration