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

provider version constraint with interpolation causes panic #15742

Closed
blalor opened this issue Aug 6, 2017 · 6 comments · Fixed by #16867
Closed

provider version constraint with interpolation causes panic #15742

blalor opened this issue Aug 6, 2017 · 6 comments · Fixed by #16867
Assignees

Comments

@blalor
Copy link
Contributor

blalor commented Aug 6, 2017

Terraform Version

Terraform v0.10.0

Terraform Configuration Files

provider "aws" {
    version = "${var.provider_version}"
}

Debug Output

crash.log.txt

Panic Output

See debug output above.

Expected Behavior

A user-friendly error should have been displayed indicating that the version constraint is invalid. Eventually it would be great to be able to specify provider versions via a variable, so that they can be defined consistently across modules.

Actual Behavior

Panic on terraform plan.

Steps to Reproduce

  1. terraform plan
@apparentlymart
Copy link
Contributor

Thanks for reporting this, @blalor.

Indeed this should be a proper error message, rather than a panic. There is supposed to be some earlier code that validates the config before we reach this point, but evidently it's not getting run for some reason and so I imagine this crash would apply for any invalid version constraint string.


As an aside, this message in your log is surprising to me:

2017/08/06 07:59:26 [INFO] Failed to read plugin lock file .terraform/plugins/darwin_amd64/lock.json: open .terraform/plugins/darwin_amd64/lock.json: no such file or directory

This file is supposed to be created by terraform init so that Terraform can "remember" which plugins it selected during the initialization phase. The fact that this file didn't exist should've triggered an error prompting you to run terraform init to create it, so it seems that there's two different strange things going on here.

@apparentlymart apparentlymart self-assigned this Aug 7, 2017
@blalor
Copy link
Contributor Author

blalor commented Aug 8, 2017

I actually hadn't run terraform init in this project. :-) I was trying to refactor some existing code, so init had already been run. In fact, if I run terraform init with the exact config contents above in an otherwise-empty directory I get:

Error getting plugins: module root: 1 error(s) occurred:

* provider.aws: invalid version constraint "${var.provider_version}": Malformed constraint: ${var.provider_version}

Removing the version = "…" line and running terraform init does work, and the lock file is created.

If I then add the version line back and run terraform plan, the panic comes back.

@MikeMcMahon
Copy link

interpolation appears to work on all provider attributes except for the version attribute.

@hopkinsth
Copy link

Just wanted to add second (or third) voice to this w/log: this panic does seem to happen for any bad version constraint, given, e.g.

provider "aws" {
  region = "us-east-1"
  version = "~1.3"
}

...you might get a crash log like the one attached: crash.log

Not a huge problem, of course. The panic makes the intended effect but contradicts the all-caps warnings.

@apparentlymart
Copy link
Contributor

Thanks for the updates here everyone, and sorry for the silence.

Based on what @blalor reported, it sounds like the code that deals with checking that all the constraints are met when running any command other than terraform init is not correctly running the validation step.

terraform init itself is catching it, but if you skip running terraform init for some reason then the intent is for Terraform to tell you that you need to run it, which requires loading the configuration to compare to what was present at the most recent terraform init call. That load to do the check must be missing a validation pass, which then causes a crash when it tries to compare the version constraints against what was expected.

Probably some things are just happening in the wrong order here. I'll take a look and find the right place to insert the required validation check here so we can produce the expected error message in all cases.

@ghost
Copy link

ghost commented Apr 5, 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 and limited conversation to collaborators Apr 5, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants