Search code examples
amazon-web-servicesterraforminfrastructure-as-code

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


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?


Solution

  • 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.