Tutorial code: conflicting provider version constraints?

Hi, I’m following the Target Resources tutorial and I get the following failure when I run the terraform init setup step:

│ Error: Failed to query available provider packages
│
│ Could not retrieve the list of available versions for provider hashicorp/aws: locked provider registry.terraform.io/hashicorp/aws 3.39.0 does not match configured version
│ constraint ~> 3.39.0, >= 3.50.0; must use terraform init -upgrade to allow selection of new versions

Running terraform init -upgrade results in this similar error message:

│ 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.39.0, >= 3.50.0

It looks like the ~>3.39.0 version specified in ./main.tf conflicts with the >=3.5.0 contraint from the s3_bucket module (.terraform/modules/s3_bucket/versions.tf).

I’ve tried cloning a clean version of the tutorial repository and keep running into this error. Is this a problem with my local configuration or with the tutorial code? If the latter, what’s the best way to move past this? Should I adjust one of the constraints manually to resolve the conflict?

thanks!

Hi @gonfy

Did you ever found a solution for it? We are facing the same as you described.

Regards
Frits

Hi @gonfy, @frederiksf,

It looks like things have changed in that example repository recently, so I’m not sure what was specified at the time of the original question, but I can confirm that the current state of that example repository isn’t valid:

That configuration depends on an external module terraform-aws-modules/s3-bucket/aws which has an upper-bounded type constraint on the AWS provider:

https://github.com/terraform-aws-modules/terraform-aws-s3-bucket/blob/940de5cbfff5688f57de5924dcd6748908e7c97d/versions.tf#L5-L9

Since the root module has now been updated for the S3-related changes in AWS provider version v4.0.0, the root module and the child module have incompatible provider requirements.

From looking at the history in that module it seems like the module authors have intentionally constrained the AWS provider version because the module isn’t yet ready to support AWS provider version v4.0.0, and so this is a correct error in the sense that there is no single provider version that’s compatible with both the root module and the child module.

Until that upstream module is ready to support the new provider version, I think the workaround I would suggest is to roll back to an earlier version of the module from the tutorial, which uses a version of the AWS provider that is compatible with the child module:

git checkout 4f83acad0041ed601234570ac71c6e8d72a1ad16

Since this is just a raw commit ID, rather than a named branch, Git will report that it is in a “detached HEAD” state after running this command, which means that there is no selected branch and thus nowhere for new commits to be added. The tutorial doesn’t require making any new commits though, so being in that special state should not hurt the ability to complete the tutorial.

Actually, even that isn’t sufficient because the external module is constrained to a particular minor version of the provider, and so it won’t accept the newer minor version that the root module is constrained to.

I was able to get it to initialize by first rolling back to an older commit as I previously mentioned and then editing main.tf to weaken the version constraint for the provider so it would be compatible with what the upstream module requires:

diff --git a/main.tf b/main.tf
index 0b5230e..bb5f2ad 100644
--- a/main.tf
+++ b/main.tf
@@ -2,7 +2,7 @@ terraform {
   required_providers {
     aws = {
       source  = "hashicorp/aws"
-      version = "~> 3.39.0"
+      version = "<= 4.0.0"
     }
 
     random = {

Hopefully we can get the source repository straightened out before too long, but until then I hope this workaround will be useful.