Terraform: Better error message for invalid and missing module key

Created on 1 Oct 2015  ยท  11Comments  ยท  Source: hashicorp/terraform

Terraform threw this error which was not that useful for me. After some minutes debugging I realized my mistake (filename should be source):

module "cloud_config" {
  filename = "../classic-cloud-config"
}
Error loading Terraform: Error downloading modules: module cloud_config: invalid source string:

A more helpful message might have been _like_:

Error loading Terraform: Error downloading modules:

module "cloud_config"
---------------------
1. Missing field "source"
2. Invalid field "filename"

An even more helpful message would show coloured arrows pointing to the offending line/column of source code.

bug config

Most helpful comment

I tried the invalid configuration given in the original comment here against Terraform v0.12-alpha1. Here's what it produced:

Error: Missing Required Attribute on module-source-error.tf line 3. The attribute "source" is required, but no definition was found.

There is clearly still some room for improvement here, but the shortcomings are general things that will be fixed in later improvements to the diagnostic snippet printer: it currently doesn't pick a very good source location to report the absence of something (it's using the closing brace of the containing block, whereas the block header would be better) and the snippet printer is missing its usual extra annotation , in module "cloud_init" for the same reason. We'll address those though incremental improvements to the diagnostics system in later releases.

The original request here also mentioned indicating that filename is not a supported argument, which is still not part of the newer error message here. Unfortunately that is not something we can practically do here because we need to be able to install the module before we can know which input variables it declares, and so Terraform defers validating the _other_ arguments in the block until the module source code is already installed.

The key point here though is being clearer that the source argument is required but not set, and I think that this new error message meets that need, and so I'm going to close this for now and we'll make one or more new issues later when we have some specific plans for continued improvement of the configuration snippet rendering for missing required arguments.

This new error message will also be included in the final release of Terraform v0.12.0. Thanks for your patience here, all!

All 11 comments

+1

:+1: Great suggestion.

Just ran into this issue today. Would love more detailed output.

oh _YES_ PLEASE!

+1

+1

+5 :)

Hi all! Sorry for this confusing error message.

The revamped configuration language parser we've been working on has better handling of missing and extra attributes, so it may "just work" and make this error message better. We have an opt-in alpha version of this coming soon where we can give it a try. If not, the new config parser at least gives us better tools for producing good error messages with proper source location information, so we should be able to get this sorted out.

We'll use this issue as a reminder to check out this case once the new config parser is in place.

+1

I tried the invalid configuration given in the original comment here against Terraform v0.12-alpha1. Here's what it produced:

Error: Missing Required Attribute on module-source-error.tf line 3. The attribute "source" is required, but no definition was found.

There is clearly still some room for improvement here, but the shortcomings are general things that will be fixed in later improvements to the diagnostic snippet printer: it currently doesn't pick a very good source location to report the absence of something (it's using the closing brace of the containing block, whereas the block header would be better) and the snippet printer is missing its usual extra annotation , in module "cloud_init" for the same reason. We'll address those though incremental improvements to the diagnostics system in later releases.

The original request here also mentioned indicating that filename is not a supported argument, which is still not part of the newer error message here. Unfortunately that is not something we can practically do here because we need to be able to install the module before we can know which input variables it declares, and so Terraform defers validating the _other_ arguments in the block until the module source code is already installed.

The key point here though is being clearer that the source argument is required but not set, and I think that this new error message meets that need, and so I'm going to close this for now and we'll make one or more new issues later when we have some specific plans for continued improvement of the configuration snippet rendering for missing required arguments.

This new error message will also be included in the final release of Terraform v0.12.0. Thanks for your patience here, all!

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

thebenwaters picture thebenwaters  ยท  3Comments

ketzacoatl picture ketzacoatl  ยท  3Comments

ronnix picture ronnix  ยท  3Comments

c4milo picture c4milo  ยท  3Comments

pawelsawicz picture pawelsawicz  ยท  3Comments