-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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 version config detection #789
Terraform version config detection #789
Conversation
f49d253
to
c5384c7
Compare
I don't understand. Why is the CI failing? Seems like it had trouble installing the dependency. |
c5384c7
to
4e696bb
Compare
@lkysow This is working on when I do |
You probably need to run |
Codecov Report
@@ Coverage Diff @@
## master #789 +/- ##
=========================================
Coverage ? 72.78%
=========================================
Files ? 63
Lines ? 4836
Branches ? 0
=========================================
Hits ? 3520
Misses ? 1055
Partials ? 261
Continue to review full report at Codecov.
|
@lkysow Ahhhh awesome thanks! Fixed!!! Love to hear your feedback/review for this PR! :) |
Actually I was thinking, with this PR we can output useful information for the users such as Some use cases:
Combined with https://github.com/runatlantis/atlantis/blob/master/CHANGELOG.md#v090 . There is potential to select the right way to generate relevant environment variables for the providers use. We only have to provide the information, users can write the logic themselves. |
We are in the process of migrating from TF 0.11 to TF 0.12 across our mono-repo with multiple terraform "modules" (subdirs). Currently we use atlantis automatic mode for project detection, so we have no place to specify per-module terraform version. We bump |
Thanks @zytek ! Let me know if it breaks anything. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good! I have a couple comments.
Also can you split up the vendor updates and the code changes into two commits. I will want to do the vendoring myself just to be safe.
This sounds cool. In a separate ticket I'd be interested in some concrete use-cases. |
9d9f5d8
to
2d2e51f
Compare
Splitted the pr into two commits |
Just tested newest version ( What I expected: What is actually happening: When there is no default version, I've ran When I ran
How to reproduce:
In logs I could see |
8c676c2
to
51ddfbb
Compare
Odd. I just added a test for multiple directory repo. It worked. |
@kennethtxytqw any idea how can we assist in testing this? Our setup with @byakku is rather simple. One repo with a few dirs (ecr/ s3/ iam/ etc) and in each dir there is edit: we have no atlantys.yaml file and rely only on atlantis autodiscovery/autodetection of projects Example output from terraform-confit-inspect running in a dir:
|
@zytek Why are there two ? Did you specify
|
@kennethtxytqw we had version specified in Atlantis could provide more helpful error message in such case :) Testing this PR agains proper project with only one version constrain right now. |
re := regexp.MustCompile(`^=?\s*([^\s]+)\s*$`) | ||
matched := re.FindStringSubmatch(module.RequiredCore[0]) | ||
if len(matched) == 0 { | ||
ctx.Log.Warn("did not specify exact version in terraform configuration.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would unify log levels here or switch those message priorities as the fact that a version was detected and is being use is IMHO more important than the fact that we fallback to defaults because no version was detected.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm you make sense. I will update my PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added some more logs and unified as you suggested.
I can confirm now that this PR works as expected. One note added regarding log levels. Just remember to not shoot yourself in the foot by leaving autogenerated versions.tf file and by deploying wrong docker image of atlantis ;-) |
HAHA got it! Thanks for testing it out. I tested it out too with this image https://hub.docker.com/r/yesyouken/atlantis feel free to use this one for testing |
51ddfbb
to
ceffad7
Compare
35a83d5
to
1c624bd
Compare
I have tested this at my workplace for more than a week already. We have deprecated the use of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work, awesome PR
Anyone up for adding a mention of this in the documentation? 😅 https://www.runatlantis.io/docs/terraform-versions.html Took a while for me to find this PR and see that this was actually really supported. ❤️ |
@MPV do you feel up to it? You can edit it here: https://github.com/runatlantis/atlantis/blob/master/runatlantis.io/docs/terraform-versions.md |
My bad should have done so in the same PR. |
Why do general version constraints on the terraform.required_version 'not make sense'? |
TLDR
testing.TempDir
Assumptions made
Only when the user specify an exact version in the terraform configuration then do we use it. The specification requirements are in https://www.terraform.io/docs/configuration/terraform.html#specifying-a-required-terraform-version
Anything else doesn't really make sense, we can fall back on server config as explained below(##Assumptions.2).
Version specified in
atlantis.yaml
takes precedence:atlantis.yaml
repo config >terraform.required_version
>defaultTfVersion
in atlantis server configThis way requires the least change to existing code.
Use of github.com/hashicorp/go-version
Offload interpretation of version number to the library.
Closes #71