Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: Invalid provider version constraints #26631

Closed
danieladams456 opened this issue Oct 19, 2020 · 5 comments · Fixed by #26637
Closed

Error: Invalid provider version constraints #26631

danieladams456 opened this issue Oct 19, 2020 · 5 comments · Fixed by #26637
Labels
bug confirmed a Terraform Core team member has reproduced this issue
Milestone

Comments

@danieladams456
Copy link

danieladams456 commented Oct 19, 2020

Terraform Version

Terraform v0.14.0-beta1

Terraform Configuration Files

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

  required_version = ">= 0.14"
}

Debug Output

https://gist.github.com/danieladams456/2a62510f5646fb073647f9e367c68062

Expected Behavior

terraform init should be able to be run twice.

Actual Behavior

The second time terraform init runs, it errors. This seems to be due the required_providers using a single version string like "3.11" and it being saved in the lock file as "3.11.*".

Steps to Reproduce

  1. terraform init
  2. terraform init

Additional Context

.terraform.lock.hcl contents:

# This file is maintained automatically by "terraform init".
# Manual edits may be lost in future updates.

provider "registry.terraform.io/hashicorp/aws" {
  version     = "3.11.0"
  constraints = "3.11.*"
  hashes = [
    "h1:J+FDe23QpxhMKYDh9xGrr+9HcWIAkyodIZXvUvuxpDY=",
  ]
}

References

#26524

@danieladams456 danieladams456 added bug new new issue not yet triaged labels Oct 19, 2020
@alisdair alisdair added confirmed a Terraform Core team member has reproduced this issue and removed new new issue not yet triaged labels Oct 19, 2020
@alisdair
Copy link
Contributor

alisdair commented Oct 19, 2020

Thanks for reporting this! I've confirmed the issue.

The specific error output on second run of terraform init is:

$ tf init

Initializing the backend...

Error: Invalid provider version constraints

  on .terraform.lock.hcl line 6:
  (source code not available)

The recorded version constraints for provider
registry.terraform.io/hashicorp/aws are invalid: invalid specification
"3.11.*": can't use wildcard for patch number; omit segments that should be
unconstrained.


Error: Invalid provider version constraints

  on .terraform.lock.hcl line 6:
  (source code not available)

The recorded version constraints for provider
registry.terraform.io/hashicorp/aws must be written in normalized form: "".

@alisdair
Copy link
Contributor

There's a possible fix for this in #26637, although I'm not completely sure that's the right approach.

One thing to note here is that I don't think Terraform intentionally supports the major.minor version constraint that you wrote in your original configuration. This is currently equivalent to writing major.minor.0, and if the configuration had included 3.11.0 from the start, I believe this bug would not have been triggered.

With that in mind, a different fix might be to make the version constraint in the original configuration invalid, with a useful diagnostic explaining what the alternatives are.

@danieladams456
Copy link
Author

As terraform is moving closer to 1.0, is now the time to tighten up on version specifiers since the behavior is not exactly explicit on just major.minor?

@alisdair
Copy link
Contributor

Yeah, I think it would be helpful to have a deprecation for version constraints with no operator and fewer than three version segments.

@ghost
Copy link

ghost commented Nov 21, 2020

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.

@ghost ghost locked as resolved and limited conversation to collaborators Nov 21, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug confirmed a Terraform Core team member has reproduced this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants