Terraform: Error: Failed to query available provider packages

Created on 10 Sep 2020  ยท  4Comments  ยท  Source: hashicorp/terraform

Trying to run terraform init and getting the following error message:

Successfully configured the backend "s3"! Terraform will automatically
use this backend unless the backend configuration changes.

Initializing provider plugins...
- Finding hashicorp/aws versions matching "3.5.0, ~> 3.5.0, ~> 2.53"...

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.5.0, ~> 3.5.0, ~> 2.53

The following are my config files.

providers.tf

terraform {
  required_version = ">= 0.13"
}

provider "aws" {
  version                 = "~> 3.5.0"
  region                  = "eu-west-2"
  shared_credentials_file = "~/.aws/credentials"
}

And versions.tf

terraform {
  required_version = ">= 0.13"
  required_providers {
    aws = {
      source = "hashicorp/aws"
      version = "3.5.0"
    }
  }
}

I've searched online for solutions and tried a couple of things from the documentation and git but always get the same error. Any help is appreciated.

bug working as designed

All 4 comments

I am having this same issue. I booted up a fresh, clean install of Ubuntu, installed Terraform 0.13.2, and did a few tests. I used the following simple configuration:

# main.tf

terraform {
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "2.70.0"
    }
  }
}

provider "aws" {
  region  = "us-east-1"
}

data "aws_iam_account_alias" "account" {
}

output "account" {
  value = data.aws_iam_account_alias.account.account_alias
}

When I run terraform init, everything works fine.

$ terraform init

Initializing the backend...

Initializing provider plugins...
- Finding hashicorp/aws versions matching "2.70.0"...
- Installing hashicorp/aws v2.70.0...
- Installed hashicorp/aws v2.70.0 (signed by HashiCorp)

Terraform has been successfully initialized!

Then, I upgrade the aws provider version to 3.5.0 and run terraform init and again, everything is fine:

$ terraform init

Initializing the backend...

Initializing provider plugins...
- Finding hashicorp/aws versions matching "3.5.0"...
- Installing hashicorp/aws v3.5.0...
- Installed hashicorp/aws v3.5.0 (signed by HashiCorp)

Terraform has been successfully initialized!

HOWEVER: If I run the _same_ tests above, but this time with the following in ~/.terraformrc, I run into trouble:

# ~/.terraformrc
plugin_cache_dir = "$HOME/.terraform.d/plugins"

First, let's clean up from past tests:

$ rm -rf ~/.terraform.d
$ rm -rf .terraform
$ mkdir -p ~/.terraform.d/plugins

Running terraform init again yields:

$ terraform init

Initializing the backend...

Initializing provider plugins...
- Finding hashicorp/aws versions matching "2.70.0"...
- Installing hashicorp/aws v2.70.0...
- Installed hashicorp/aws v2.70.0 (signed by HashiCorp)

Terraform has been successfully initialized!

We can see that the aws provider was installed to a common location and symlinked:

$ ll .terraform/plugins/registry.terraform.io/hashicorp/aws/2.70.0/
total 12
drwxr-xr-x 2 root root 4096 Sep 10 15:47 ./
drwxr-xr-x 3 root root 4096 Sep 10 15:47 ../
lrwxrwxrwx 1 root root   81 Sep 10 15:47 linux_amd64 -> /root/.terraform.d/plugins/registry.terraform.io/hashicorp/aws/2.70.0/linux_amd64/

Now, if I upgrade the provider version to 3.5.0, chaos ensues:

$ terraform init

Initializing the backend...

Initializing provider plugins...
- Finding hashicorp/aws versions matching "3.5.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 3.5.0

@LunaticZorr Your provider constraints are unsatisfiable. It looks like you have multiple constraints, probably in several locations in your configuration. 3.5.0 and ~> 3.5.0 are compatible, but, ~> 2.53 basically means > 2.0.0, < 3.0.0. As you can imagine, you can't install a provider version which is both equal to 3.5.0 and < 3.0.0.

The fix for this is to find which module or file contains the additional version constraint, and update it so that all of them are compatible.

I hope this explains the problem you're seeing. This does not seem to be a bug in Terraform, so I'm going to close this issue.

@jcarlson The plugin cache problem you're seeing seems to be separate, and I can reproduce it. Please report it as another issue so that it can be investigated. Thanks in advance!

Opened #26223

I'm going to lock this issue because it has been closed for _30 days_ โณ. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

thebenwaters picture thebenwaters  ยท  3Comments

rjinski picture rjinski  ยท  3Comments

ronnix picture ronnix  ยท  3Comments

larstobi picture larstobi  ยท  3Comments

rjinski picture rjinski  ยท  3Comments