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

Terraform doesn't understand pre-release required_version constraint #28148

Closed
marshall7m opened this issue Mar 20, 2021 · 8 comments · Fixed by #31331
Closed

Terraform doesn't understand pre-release required_version constraint #28148

marshall7m opened this issue Mar 20, 2021 · 8 comments · Fixed by #31331
Labels
bug confirmed a Terraform Core team member has reproduced this issue explained a Terraform Core team member has described the root cause of this issue in code v0.15 Issues (primarily bugs) reported against v0.15 releases

Comments

@marshall7m
Copy link

marshall7m commented Mar 20, 2021

Terraform Version

0.15.0-beta2

Terraform Configuration Files

terraform
terraform {
  required_version = "0.15.0-beta2"
}

output "test" {
    value = "foo"
}

Debug Output

Crash Output

Expected Behavior

Outputs:

test = "foo"

Actual Behavior

│ Error: Unsupported Terraform Core version
│ 
│   on main.tf line 2, in terraform:
│    2:   required_version = "0.15.0-beta2"
│ 
│ This configuration does not support Terraform version 0.15.0-beta2. To proceed, either choose
│ another supported Terraform version or update this version constraint. Version constraints are
│ normally set for good reason, so updating the constraint may lead to other errors or unexpected
│ behavior.

Steps to Reproduce

  1. `terraform apply

Additional Context

Using tfenv for Terraform version management. Specifically using tfenv use 0.15.0-beta2 before running terraform apply

References

@marshall7m marshall7m added bug new new issue not yet triaged labels Mar 20, 2021
@alisdair alisdair added confirmed a Terraform Core team member has reproduced this issue v0.15 Issues (primarily bugs) reported against v0.15 releases and removed new new issue not yet triaged labels Mar 22, 2021
@alisdair
Copy link
Member

Hi @marshall7m, thanks for reporting this. I can see this behaviour too.

This is caused by the version package initializing the SemVer variable without the Prerelease field. I think we should be able to update that, but there may be some reason why we don't support constraints against the prerelease field that I'm not aware of.

@alisdair alisdair added the explained a Terraform Core team member has described the root cause of this issue in code label Mar 22, 2021
@alisdair
Copy link
Member

An update after a failed attempt to fix this: while the issue is at root caused by this mismatched SemVer value, this is too load bearing to change. Instead I think we should try updating the specific location where we check the Terraform version against the constraints, and use the prerelease only in that spot.

@marshall7m
Copy link
Author

thanks @alisdair for taking a look at this. I'm not too familiar with the internal aspects of Terraform (and Go in general) but it seems like your PR will fix it. Thanks!

@marshall7m
Copy link
Author

marshall7m commented Mar 23, 2021

I don't know if this helps or brings up another issue but when I use required_version = "0.15.0" within all modules used within the target Terraform configuration, Terraform doesn't raise a version constraint error when I use Terraform version 0.15.0-beta2.

@bflad
Copy link
Member

bflad commented Nov 3, 2021

FYI, this also happens when locally installing Terraform CLI. For example, terraform version and the version error will output 1.0.11-dev but the constraint must be 1.0.11.

@alisdair
Copy link
Member

alisdair commented Nov 3, 2021

I just reinvestigated implementing the second idea I had posted above, and it's also a non-starter. If we consider the full version (including prerelease) when calculating required_version compliance, modules with constraints like >= 0.12.0 will fail with any prerelease version.

This is because go-version rejects prerelease versions for constraints which use inequality checks. Making the change I suggested would break the use of modules with any prerelease build.

At the risk of being wrong for the third time in a row, I think the only useful thing we can do here is warn or error if the required_version field contains a prerelease version number.

@bflad
Copy link
Member

bflad commented Nov 3, 2021

That sounds reasonable to me 👍

@github-actions
Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 31, 2022
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 explained a Terraform Core team member has described the root cause of this issue in code v0.15 Issues (primarily bugs) reported against v0.15 releases
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants