Skip to content
This repository has been archived by the owner on Oct 8, 2020. It is now read-only.

Template provider - Better error message at template parsing #63

Open
oonisim opened this issue Jun 14, 2019 · 2 comments
Open

Template provider - Better error message at template parsing #63

oonisim opened this issue Jun 14, 2019 · 2 comments

Comments

@oonisim
Copy link

oonisim commented Jun 14, 2019

When the template file includes string such as ${$name}, terraform complains the tf file is incorrect although the error is in the template file.

Error: failed to render : <template_file>:1,4-5: Invalid character; This character is not used within the language., and 1 other diagnostic(s)

  on ecs_task.tf line 1, in data "template_file" "hoge":
   1: data "template_file" "hoge" {

Terraform Version

Run terraform -v to show the version. If you are not running the latest version of Terraform, please upgrade because your issue may have already been fixed.

Terraform v0.12.2
+ provider.aws v2.15.0
+ provider.local v1.2.2
+ provider.null v2.1.2
+ provider.template v2.1.2

Affected Resource(s)

  • template_file

Terraform Configuration Files

Template file content

"${$name}"

tf file content

data "template_file" "hoge" {
  template = file("path/to/template")
  vars = {
    name          = var.service_name
  }
}

Debug Output

Panic Output

Expected Behavior

Terraform error points to the template file, not the tf file.

Actual Behavior

Terraform error message is not helpful to identify the cause.

Steps to Reproduce

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

  1. terraform apply

Important Factoids

References

@apparentlymart
Copy link
Contributor

Hi @oonisim,

If you are using Terraform 0.12 then I strongly recommend considering template_file to be deprecated and using the templatefile function instead. Although it's not officially deprecated in the code (because we can't distinguish deprecations between 0.12 and 0.11 while the provider is still cross-compatible), the templatefile function works better because it's integrated into Terraform itself rather than being implemented in a provider.

I believe the templatefile function also reports the problem from the perspective of the function call rather than inside the template file itself. That's a limitation of the fact that template files are not configuration files and are thus not available for use in configuration snippets. Hopefully the presentation of the error is better though, because the function is not forced to marshal its errors through the constraints of the 0.11-compatible Terraform SDK.

@cruftyoldsysadmin
Copy link

cruftyoldsysadmin commented Aug 6, 2019

@apparentlymart Do you have any full usage examples of templatefile? The documentation for this is fairly sparse and incomplete.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants