Terraform: “no available releases match the given constraints

By | 08/06/2025
 

A fairly common error when upgrading module versions, when there are restrictions on module or provider versions, and they do not match each other.

The Issue

In this case, I merged Pull Requests from Renovate and didn’t notice that terraform-aws-modules/terraform-aws-lambda needed hashicorp/aws provider version 6:

And first I upgraded Lambda to version 8.

After that when running terraform init I received the “no available releases match the given constraints” error:

$ terraform init
Initializing the backend...
Upgrading modules...
...
│ 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 >= 3.29.0, ~> 5.14, >= 5.92.0, >= 6.0.0
...

The cause

To see which provider versions are used in which modules, run terraform providers, and you will get a dependency tree with all versions:

$ terraform providers

Providers required by configuration:.

├── provider[registry.terraform.io/hashicorp/aws] ~> 5.14
...
└── module.atlas_monitoring
    ...
    ├── module.single_ingress_alb_logs_loki
    │   ├── provider[registry.terraform.io/hashicorp/aws]
    │   ├── module.logs_promtail_lambda
            ...
    │       ├── provider[registry.terraform.io/hashicorp/aws] >= 6.0.0
            ...
    ├── module.logs_promtail_lambda_rds_kraken_loki
        ...
    │   └── provider[registry.terraform.io/hashicorp/aws] >= 6.0.0
    ├── module.logs_promtail_lambda_rds_kraken_vmlogs
        ...
    │   └── provider[registry.terraform.io/hashicorp/aws] >= 6.0.0
    ├── module.logs_promtail_lambda_rds_os_metrics_loki
        ...
    │   ├── provider[registry.terraform.io/hashicorp/aws] >= 6.0.0
        ...
    └── module.logs_promtail_lambda_rds_os_metrics_vmlogs
        ├── provider[registry.terraform.io/hashicorp/aws] >= 6.0.0
        ...

This is where we see the problem:

  • provider[registry.terraform.io/hashicorp/aws] ~> 5.14
  • module.logs_promtail_lambda_rds_kraken_loki : provider[registry.terraform.io/hashicorp/aws] >= 6.0.0

And the error tells us “given constraints >= 3.29.0, ~> 5.14, >= 5.92.0, >= 6.0.0“, i.e.:

  • First requirement: versions higher than 3.29.0
  • In the third condition, we have a pessimistic constraint: in “~> 5.14,” we allow any versions from 5.14.0 to, but not including 6.0.0, i.e. patches for 5.14, or versions 5.15.x and above (see Version Constraints).
  • and the last condition requires >= 6.0.0 – version 6 and higher

The condition ~> 5.14 is set in the main module atlas_monitoring in versions.tf:

terraform {

  required_version = "~> 1.5"

  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 5.14"
    }
...

The solution

Here, there is an option to upgrade hashicorp/aws in atlas_monitoring to version 6, but there were some breaking changes (which I noticed 🙂 ) that needed to be checked, so I didn’t rush into it at that point.

Another solution is to simply revert the Pull Request merge with an upgrade of terraform-aws-modules/terraform-aws-lambda:

Then, first update hashicorp/aws to version 6, and then update the module with Lambda.