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

Allow additional specifiers in terraform's required_version other than = e.g. ~> and > #1217

Closed
llamahunter opened this issue Oct 11, 2020 · 12 comments · Fixed by #1776
Closed
Labels
feature New functionality/enhancement

Comments

@llamahunter
Copy link
Contributor

Currently, it appears that the code in project_command_builder.go only accepts terraform.required_version specifications that exactly specify a single version, rather than a range or other version constraint. Seems odd to have this limited behavior, as atlantis is built to support a wide range of terraform versions. It seems that the version constraints should be interpreted and the latest matching terraform version selected.

Also, the silent failure of the current approach is misleading.

@llamahunter
Copy link
Contributor Author

Is there a reason why this was not implemented? Looking at the code, it seems reasonably straightforward to do so. Just need to get the list of all available terraform versions, which can be pulled from https://api.github.com/repos/hashicorp/terraform/tags

@llamahunter
Copy link
Contributor Author

Or, slightly more hackily, could parse the HTML returned from ${TFDownloadURL}/terraform to get all the version numbers. But, that presumes that whatever URL is configured works similar to https://releases.hashicorp.com/terraform and provides a link tree.

@lkysow lkysow added the feature New functionality/enhancement label Oct 23, 2020
@lkysow
Copy link
Member

lkysow commented Oct 23, 2020

I think this was likely not implemented because it makes the behaviour non-deterministic or because it was too difficult. I didn't implement it though so I can't say for sure :)

@grimm26
Copy link
Contributor

grimm26 commented Nov 12, 2020

@llamahunter so you would want atlantis to download all terraform versions that match your non-exact constraint? It can't use that info to set a default version to use, though.

@llamahunter
Copy link
Contributor Author

I would want it to download the most recently available version that matches the version constraint.

@scruplelesswizard
Copy link
Contributor

scruplelesswizard commented Nov 12, 2020

Per the semver spec (which Terraform follows), the version with the greatest precedence shall be selected.

If a user wants to use a specific version of Terraform they can indicate that by using a = constraint.

The Terraform documentation specifically covers the Version Constraint Syntax and Version Constraint Behavior

@jlestrada
Copy link

jlestrada commented Feb 10, 2021

Any update on this request? It seems odd that this is considered a feature as opposed to a bug since it is ignoring the version constraint syntax that is supported by terraform. We have had to modify our version constraint from what we do with local development work to fit the needs of atlantis (to be explicit in version number).

Happy to help contribute as well if this is agreed to be something that can be supported! Seems like a number of members are facing similar issues.

Ah my mistake, looks like this PR is in review but just taking some time to get out the door. I just need to be patient 😄

@scruplelesswizard
Copy link
Contributor

@jlestrada Feel free to give the PR a review if you have the cycles. I'm sure that would help it land more quickly

@mcaulifn
Copy link

Will #1266 also read from .terraform-version?

@scruplelesswizard
Copy link
Contributor

scruplelesswizard commented Feb 25, 2021

@mcaulifn It uses the Terraform code to do the ingest and interpretation of versions, so the behaviour will be identical to that of Terraform

@llamahunter
Copy link
Contributor Author

what's the status of this? The PR that was purportedly going to fix this (#1266) was abandoned.

@nitrocode
Copy link
Member

It seems that PR #1266 was abandoned @llamahunter and the branch was also deleted very recently.

FWIW, in recent versions of terraform such as 0.15.x and 1.x, we do not have to worry so much about tfstate since the tfstate is backwards compatible. For terraform root modules that have been upgraded to 1.x, I use the default atlantis version which is the latest terraform version and I use a required_version = "> 1.0" and it just works.

I'd be in favor of another PR (or the same PR if the branch was undeleted and rebased) that would allow more than just required_version = "=1.3.5" such as ~> expressions.

One downside of this proposed change is that if you were to set the constraint to ~> 1.3 it would download 1.3.5 today and then as new versions came out, it would also download 1.3.6, 1.3.7, etc until 1.4.x was released. Each binary is about 80 MB and could fill up your volume.

If the change to support > and ~> is added, perhaps it should also remove older versions (if they haven't been accessed in awhile) but that may be tricky to do if you have a mixture of = x.x.x and ~> x.x.x. On second thought, if the above proposed feature (not the stale tf removal) was implemented then perhaps removing the stale binaries should be the responsibility of the developer using atlantis.

@nitrocode nitrocode changed the title atlantis does not interpret terraform.required_version specifiers other than '=' Allow additional specifiers in terraform's required_version other than '=' Nov 19, 2022
@nitrocode nitrocode changed the title Allow additional specifiers in terraform's required_version other than '=' Allow additional specifiers in terraform's required_version other than = e.g. ~> and `>~ Nov 19, 2022
@nitrocode nitrocode changed the title Allow additional specifiers in terraform's required_version other than = e.g. ~> and `>~ Allow additional specifiers in terraform's required_version other than = e.g. ~> and > Nov 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New functionality/enhancement
Projects
None yet
7 participants