hashicorp / terraform-provider-template

Terraform template provider
https://www.terraform.io/docs/providers/template/
Mozilla Public License 2.0
130 stars 89 forks source link

Template provider - Better error message at template parsing #63

Open oonisim opened 5 years ago

oonisim commented 5 years ago

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)

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 commented 5 years ago

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 commented 4 years ago

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