Terraform: resolve "no available releases match the given constraints" error
Asked Answered
L

1

8

I am trying to update hashicorp/aws provider version.

I added terraform.tf file with following content:

terraform {
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 4.0"
    }
  }
}

Later I tried to update modules using:

terraform init -upgrade

However, I have started to get:

Could not retrieve the list of available versions for provider hashicorp/aws: 
no available releases match the given constraints >= 2.0.0, ~> 3.27, ~> 4.0

How could this problem be resolved?

Lindsay answered 17/5, 2023 at 12:28 Comment(1)
Terraform could improve the output by replacing commas with "AND" ... at the same time.Feck
L
23

This is the important part of the error message.

>= 2.0.0, ~> 3.27, ~> 4.0
  1. You request a version greater than or equal to 2.0.0
  2. You prefer a version 3.27
  3. You prefer a version 4.0

Both 2 and 3 cannot be possible at the same time.

The solution for this specific case is the stop requesting 2 different versions at the same time.

Check versions of available providers:

!+?main ~/Projects/x/src/x-devops/terraform/env/test> terraform providers

Providers required by configuration:
.
├── module.test-sonar
│   └── provider[registry.terraform.io/hashicorp/aws]
├── module.client_vpn
│   └── provider[registry.terraform.io/hashicorp/aws]
├── module.test-appserver
│   └── provider[registry.terraform.io/hashicorp/aws] ~> 3.27
├── module.test-vpn-server
│   └── provider[registry.terraform.io/hashicorp/aws]
├── module.test-networking
...

There is a module which requests 3.27.

Find all modules which request 3.27 and update them to 4.0.

This should resolve such problems.

Lindsay answered 17/5, 2023 at 12:28 Comment(2)
thank you for your explain, i'm facing the same error, and this save my dayModigliani
How to update the modules?Traitor

© 2022 - 2024 — McMap. All rights reserved.