Problem
When running Terraform commands such as terraform init or terraform plan, the operation fails with an error indicating that no available provider releases match the given version constraints.
│ 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
Cause
This error occurs when Terraform cannot find a single version of a provider that satisfies all version constraints defined across the root module and all child modules. A common cause is using a module without a pinned version. An update to that module may introduce a new, more restrictive provider version requirement that conflicts with constraints defined elsewhere in your configuration.
Procedure: Diagnosing the Conflict
This procedure demonstrates how to use the terraform providers command to identify the source of a conflicting provider version constraint.
Step 1: Review the Configuration
Consider a root module that uses both a local module and a public module.
-
Root
main.tfThis configuration requires the AWS provider version
4.59.0or newer.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" } -
Local Module
module/main.tfThis local module pins the AWS provider to exactly version
5.100.0.terraform { required_providers { aws = { source = "hashicorp/aws" version = "5.100.0" } } }
Step 2: Reproduce the Error
Initialize the configuration. Terraform will fail because it cannot satisfy all constraints.
$ terraform init Initializing the backend... Initializing provider plugins... - Finding hashicorp/aws versions matching ">= 4.59.0, 5.100.0, >= 6.0.0"... ╷ │ 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
The error message shows three constraints: >= 4.59.0 (from the root module), 5.100.0 (from the local module), and an unexpected >= 6.0.0.
Step 3: Identify the Source of the Conflict
Run the terraform providers command to see where each constraint is defined.
$ 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.0The output clearly shows that the module.s3-bucket is the source of the >= 6.0.0 constraint.
Solutions
Solution 1: Pin the Module Version
Since the public s3-bucket module introduced a breaking provider requirement, you can resolve the conflict by pinning the module to an older version that has a compatible provider constraint.
-
Modify the module block in your root
main.tfto specify a compatible version. In this example, version4.11.0of the module requires AWS provider version>= 5.83, which is compatible with the other constraints.module "s3-bucket" { source = "terraform-aws-modules/s3-bucket/aws" version = "4.11.0" } -
Run
terraform init -upgradeto download the specified module version and re-initialize the providers.$ terraform init -upgrade 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)
Terraform can now find a compatible provider version (
5.100.0) and the initialization succeeds.
Solution 2: Align Provider Version Constraints
As a best practice, always pin provider versions to avoid unexpected updates. If you must upgrade a provider, update the version constraints consistently across all modules to ensure they are compatible.
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
# Use a specific, compatible version range
version = "~> 5.0"
}
}
}Outcome
After applying the fix, the terraform providers command shows a set of compatible constraints.
$ 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.0Running terraform version confirms that the correct provider version was installed.
$ terraform version Terraform v1.10.5+ provider registry.terraform.io/hashicorp/aws v5.100.0