Introduction
The following error is seen
Failed to query available provider packages and no available releases match the given constraints.
This is most likely because version pinning is missing in the code.
The following example demonstrates a module invocation without a specified version, details the resulting error, and provides instructions on utilizing the terraform providers
command to identify the locations where provider version constraints are defined.
Problem
Terraform runs fail with the error:
│ Error: Failed to query available provider packages │ │ Could not retrieve the list of available versions for provider hashicorp/aws: no available releases match the given constraints >= │ 4.59.0, 5.100.0, >= 6.0.0 │ │ To see which modules are currently depending on hashicorp/aws and what versions are specified, run the following command: │ terraform providers
Example
The following example will show the error. The example uses a local module and a public module
- main.tf (of the root module)
terraform { required_providers { aws = { source = "hashicorp/aws" version = ">=4.59.0" } } } provider "aws" { region = "eu-west-3" } module "mymodule" { source = "./module" } module "s3-bucket" { source = "terraform-aws-modules/s3-bucket/aws" }
In the required_providers
of the terraform block, we define a constraint of version 4.59.0
or higher for the AWS provider.
- module/main.tf (main.tf of the module)
terraform { required_providers { aws = { source = "hashicorp/aws" version = "5.100.0" } } }
In the module mymodule
the version for the AWS provider is defined as 5.100.0
.
- The module
s3-bucket
is a publicly available module. We have no influence on the code - Initialize the code by using
terraform init
and the following error is seen
Could not retrieve the list of available versions for provider hashicorp/aws: no available releases match the given constraints >= │ 4.59.0, 5.100.0, >= 6.0.0
The error shows the versions constraints we have given in our code, >=4.59.0
and 5.100.0
.
However, somewhere there is a version constraint of >=6.0.0
. Because we are specifically pinning to version 5.100.0
, the newly introduced constraint for >=6.0.0
can't be met and Terraform fails.
Especially in large configurations the terraform providers
command might be useful here.
(Note that this command only works with your code on the command line.)
With our code on the command line, and after the terraform init
, we can run the terraform providers
command. The output is as follows:
% terraform providers Providers required by configuration: . ├── provider[registry.terraform.io/hashicorp/aws] >= 4.59.0 ├── module.mymodule │ └── provider[registry.terraform.io/hashicorp/aws] 5.100.0 └── module.s3-bucket └── provider[registry.terraform.io/hashicorp/aws] >= 6.0.0
From this output we can see that the constraint for version >=6.0.0
is coming from module.s3-bucket
.
Looking at Github code for this module and verifying the versions.tf file it shows there is a version constraint for >=6.0.0
required_providers { aws = { source = "hashicorp/aws" version = ">= 6.0" }
Going back in the tag versions we can see that in version 4.11.0
of the module.s3-bucket
the version constraint was
required_providers { aws = { source = "hashicorp/aws" version = ">= 5.83" }
In our configuration, let’s return to the module invocation for the s3-bucket
and add a version constraint to specify module version 4.11.0
, as shown below:
module "s3-bucket" { source = "terraform-aws-modules/s3-bucket/aws" version = "4.11.0" }
Now run a terraform init -upgrade
it will show the following output
Initializing the backend... Upgrading modules... - mymodule in module Downloading registry.terraform.io/terraform-aws-modules/s3-bucket/aws 4.11.0 for s3-bucket... - s3-bucket in .terraform/modules/s3-bucket Initializing provider plugins... - Finding hashicorp/aws versions matching ">= 4.59.0, >= 5.83.0, 5.100.0"... - Installing hashicorp/aws v5.100.0... - Installed hashicorp/aws v5.100.0 (signed by HashiCorp)
It shows that the version constraints can be met and provider AWS provider version 5.100.0
is installed.
The terraform providers command now shows:
% terraform providers Providers required by configuration: . ├── provider[registry.terraform.io/hashicorp/aws] >= 4.59.0 ├── module.s3-bucket │ └── provider[registry.terraform.io/hashicorp/aws] >= 5.83.0 └── module.mymodule └── provider[registry.terraform.io/hashicorp/aws] 5.100.0
It shows that the version constraint for module.s3-bucket
has changed to >=5.83.0
.
Running the terraform version
command we can check that indeed version 5.100.0
of the AWS provider is installed.
Terraform v1.10.5 + provider registry.terraform.io/hashicorp/aws v5.100.0
Cause
Not pinning the module version, can cause an unintentional upgrade of the module. This can contain a new version constraint for a provider that conflicts with the versions constraints in the own configuration.
Solutions:
- Pin your provider versions
required_providers { aws = { source = "hashicorp/aws" version = ">= 6.0" }
- Pin your module versions as your modules can define provider versions as well
module "s3-bucket" { source = "terraform-aws-modules/s3-bucket/aws" version = "4.11.0" }
Additional Information
- Version constraints
-
terraform providers
command -
terraform version
command