-
Notifications
You must be signed in to change notification settings - Fork 9.6k
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
v0.12: Terraform Version Check Ignored depending on location #21420
Comments
Observed an odd behavior that if you remove the meta.tf and have a main.tf it works around the issue. Terraform Configuration Files$ rm meta.tf
$ cat main.tf
terraform {
required_version = "< 0.12.0"
}
output "a.b.c_unsupported" {
value = "1.2.3"
} Actual Behaviorterraform init
Error: Unsupported Terraform Core version
This configuration does not support Terraform version 0.12.0. To proceed,
either choose another supported Terraform version or update the root module's
version constraint. Version constraints are normally set for good reason, so
updating the constraint may lead to other errors or unexpected behavior. |
Unfortunately, this trick above doesn't work with nested modules. |
Hi @bernadinm! In your first example you showed a version constraint of |
That's correct. These templates are versioned controlled and we wanted to
ensure the proper version of terraform was applied until the new templates
we're migrated to.
…On Thu, May 23, 2019, 18:00 Martin Atkins ***@***.***> wrote:
Hi @bernadinm <https://github.com/bernadinm>!
In your first example you showed a version constraint of > 0.12.0. Was
that intentional? Based on everything else you've shown here, it looks like
you were trying to write a version constraint to *exclude* Terraform
0.12.0 and later.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#21420?email_source=notifications&email_token=ACCMIEVG3NMSODO4ZVU7MV3PW44ZDA5CNFSM4HPLA5PKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODWD336I#issuecomment-495435257>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ACCMIERV7MEQBX5VMROGHE3PW44ZDANCNFSM4HPLA5PA>
.
|
Thanks for the clarification. In that case, shouldn't the version constraint in your |
Thanks for the catch. You are correct. However regardless of the condition, it still ignores the required_version check. Here is a single command to help repo: mkdir -p /tmp/repo/module
cat > /tmp/repo/module/main.tf <<EOF
terraform {
required_version = "< 0.12.0"
}
output "a.b.c_unsupported" {
value = "1.2.3"
}
EOF
cat > /tmp/repo/main.tf <<EOF
module "test" {
source = "./module"
}
EOF
cd /tmp/repo/
terraform init |
Thanks! The Terraform version constraint handling tries its best to ignore errors during loading so that it can detect this situation, but it seems like it's not trying quite hard enough to deal with it here. I suspect it's handling the check on a per-file basis rather than on a whole-module basis, and so it only works if the error is in the same file as the version constraint; instead, it should visit all of the files first to sniff for version constraints, and only then move on to actually trying to load them fully. |
It looks like it is even ignoring the mkdir -p /tmp/repo/module
cat > /tmp/repo/module/main.tf <<EOF
terraform {
required_version = "< 0.12.0"
}
output "a.b.c_unsupported" {
value = "1.2.3"
}
EOF
cat > /tmp/repo/main.tf <<EOF
terraform {
required_version = "< 0.12.0"
}
module "test" {
source = "./module"
}
EOF
cd /tmp/repo/
terraform init Actual Output$ terraform init
Initializing modules...
There are some problems with the configuration, described below.
The Terraform configuration must be valid before initialization so that
Terraform can determine which modules and providers need to be installed.
Error: Invalid output name
on module/main.tf line 5, in output "a.b.c_unsupported":
5: output "a.b.c_unsupported" {
A name must start with a letter and may contain only letters, digits,
underscores, and dashes. $ terraform -v
Terraform v0.12.0
|
The original content of this comment was reporting a separate issue, and has been filed with the upstream library (hashicorp/go-version#55) responsible for version comparison |
Hi @sudoforge! Thanks for reporting that, but it seems like a separate problem, so could you please open a new issue for it? Terraform uses an upstream library to handle those, so it's possible that it had an undocumented behavior change that we inherited, but the solution to that will be independent of fixing the handling of the |
@apparentlymart You're absolutely right. My apologies, I had several different tabs open with various issues and must have gotten my wires crossed. |
good afternoon, I solve the problem by adding to require_version = "<= 0.12.19" |
In my case it worked by adding |
I am going to close this issue due to inactivity, and it looks like the questions have been answered. The underlying code paths have changed for terraform v0.13, so if you still see an issue when using the latest version of terraform, please open a new issue. Thanks! |
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. |
When using terraform v0.12, it fails to perform the check depending if the condition lives in the main.tf or any other *.tf
Terraform Version
Terraform Configuration Files
Actual Behavior
Expected Behavior
Steps to Reproduce
terraform init
The text was updated successfully, but these errors were encountered: