Terraform: Unhelpful error message when unknown variable accessed

Created on 16 Jun 2016  ยท  8Comments  ยท  Source: hashicorp/terraform

Terraform Version

0.7.0 rc2

When a variable is missing but accessed in a module, potentially many modules deep, the error message doesn't mention which file has the issue. This makes troubleshooting difficult when using other modules. Could the error reporting be enhanced to always show the file where the error occurred? Here's what I see:

Error applying plan:

1 error(s) occurred:

  • 1:3: unknown variable accessed: var.distribution in:

${var.distribution}

Terraform does not automatically rollback in the face of errors.
Instead, your Terraform state file has been partially updated with
any resources that successfully completed. Please address the error
above and apply again to incrementally change your infrastructure.

I'm seeing this while using a community module, pretty sure it's from somewhere in this chain:

module "ami" {
  source        = "github.com/terraform-community-modules/tf_aws_ubuntu_ami/ebs"
  instance_type = "${var.instance_type}"
  region        = "${var.region}"
  distribution  = "trusty"
}

Affected Resource(s)

Please list the resources as a list, for example:
any

If this issue appears to affect multiple resources, it may be an issue with Terraform's core, so please mention this.

Terraform Configuration Files

# Copy-paste your Terraform configurations here - for large Terraform configs,
# please use a service like Dropbox and share a link to the ZIP file. For
# security, you can also encrypt the files using our GPG public key.

Debug Output

Please provider a link to a GitHub Gist containing the complete debug output: https://www.terraform.io/docs/internals/debugging.html. Please do NOT paste the debug output in the issue; just paste a link to the Gist.

Panic Output

If Terraform produced a panic, please provide a link to a GitHub Gist containing the output of the crash.log.

Expected Behavior

What should have happened?

Actual Behavior

What actually happened?

Steps to Reproduce

Please list the steps required to reproduce the issue, for example:

  1. terraform apply

Important Factoids

Are there anything atypical about your accounts that we should know? For example: Running in EC2 Classic? Custom version of OpenStack? Tight ACLs?

References

Are there any other GitHub issues (open or closed) or Pull Requests that should be linked here? For example:

  • GH-1234
config enhancement

Most helpful comment

Getting a bunch of these with the latest version 0.7.9 (never was an issue with 0.7.7). They are pretty confusing as everything works correctly.

Also the amount of output shown is really distracting as it means that i need to scroll up thousands and thousands of lines to see the output of the Terraform run.

If these are for debug purposes only, please consider putting them into a file instead, not the console.

Thanks heaps!
Fotis

All 8 comments

Hi @trauts2! I agree this would be useful, but currently the information is not retained to be able to include in the error message. I think we can do a better job here, and will leave this issue open to track that work.

This ruins building abstractions in terraform :(

I am seeing this issue in combination with another terraform bug (probably the variables are there but nested modules are not being handled correctly). Due to this I cannot track the bug down to the exact module and report the issue.

+1 I seem to be getting this when issuing terraform plan -destroy

Getting this in 0.7.4 as well with terraform destroy; when running terraform apply, everything is fine.

Getting a bunch of these with the latest version 0.7.9 (never was an issue with 0.7.7). They are pretty confusing as everything works correctly.

Also the amount of output shown is really distracting as it means that i need to scroll up thousands and thousands of lines to see the output of the Terraform run.

If these are for debug purposes only, please consider putting them into a file instead, not the console.

Thanks heaps!
Fotis

Hi all! Sorry for the long silence here.

Although some gradual improvements to this have happened since the last comment here, we recently merged in to the master branch a new error output implementation that now includes full context on source locations in errors like this:

Error: Reference to undeclared input variable

  on bad-error-messages.tf line 3, in module "ami":
   3:   instance_type = "${var.instance_type}"

An input variable with the name "instance_type" has not been declared. This
variable can be declared with a variable "instance_type" {} block.


Error: Reference to undeclared input variable

  on bad-error-messages.tf line 4, in module "ami":
   4:   region        = "${var.region}"

An input variable with the name "region" has not been declared. This variable
can be declared with a variable "region" {} block.

This will be included in the forthcoming v0.12.0 release of Terraform. Since this change is already merged, I'm going to close this out now.

Thanks @apparentlymart and all the Terraform team!

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

atkinchris picture atkinchris  ยท  68Comments

amaczuga picture amaczuga  ยท  124Comments

felnne picture felnne  ยท  133Comments

phinze picture phinze  ยท  167Comments

bloopletech picture bloopletech  ยท  82Comments