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

[regression] provider-template fails rendering when template file has % in the content starting from v2.0.0 #69

Closed amgohan closed 4 years ago

amgohan commented 4 years ago

Hi there,

Terraform Version

terraform version : 0.11.14

Affected Resource(s)

Terraform Configuration Files

main.tf

data "template_file" "file" {
  template = "${file("${path.module}/file.tpl")}"
  vars = {
    name = "foo"
  }
}

output "rendered_file" {
  value = "${data.template_file.file.rendered}"
}

file.tpl

hello ${name},
%{bar}

Debug Output

data.template_file.file: Refreshing state...

Error: Error refreshing state: 1 error(s) occurred:

* data.template_file.file: 1 error(s) occurred:

* data.template_file.file: data.template_file.file: failed to render : <template_file>:2,3-6: Invalid template control keyword; "bar" is not a valid template control keyword. Did you mean "for"?

Expected Behavior

The apply should render the data.template_file.file.rendered value correctly as follows:

rendered_file = hello foo,
%{bar}

Actual Behavior

generating an error using terraform-provider-template v2.0.0 and above, but working fine in v1.0.0 * data.template_file.file: data.template_file.file: failed to render : <template_file>:2,3-6: Invalid template control keyword; "bar" is not a valid template control keyword. Did you mean "for"?

Steps to Reproduce

  1. terraform init && terraform apply
mikecook commented 4 years ago

https://github.com/terraform-providers/terraform-provider-template/blob/master/CHANGELOG.md#200-january-14-2019 HCL 2.0 template syntax includes a new %{ ... } construct for control structures, like %{ if a == b } ... %{ endif }. If your existing templates contain any %{ sequences you will need to now escape them as %%{ to ensure correct parsing.

mildwonkey commented 4 years ago

Hi! @mikecook has it right - in the provider v2.0 and later you need to escape % with as %%. Thanks!

amgohan commented 4 years ago

Thanks, my problem is solved. I didn't notice that in the Changelog.