Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keys for substitution in Template file function must begin with letter, not number #23789

Closed
andrew-lee-1089 opened this issue Jan 6, 2020 · 2 comments · Fixed by #24184
Closed
Labels
bug documentation v0.12 Issues (primarily bugs) reported against v0.12 releases

Comments

@andrew-lee-1089
Copy link

Terraform Version

0.12.18

Terraform Configuration Files

With template "metadata_template.json":

{
  "node_local": ${0_VALUE_FROM_NODE_NAMES},
  "node_remote": ${1_VALUE_FROM_NODE_NAMES},
}

and terraform config:

  "resource": {
    "local_file": {
      "user_data_a_json": {
        "content": "${templatefile(\"metadata_template.json\",  {\"0_VALUE_FROM_NODE_NAMES\": \"${jsonencode(var.node_names[0])}\", \"1_VALUE_FROM_NODE_NAMES\": \"${jsonencode(var.node_names[1])}\",
"})}",
        "filename": "${var.node_names[0]}_userdata.json"
      },

I get a

Error: Error in function call

  on main.tf.json line 59, in resource.local_file.user_data_a_json:
  59:         "content": "${templatefile(.....

Call to function "templatefile" failed:
metadata_template.json:14,20-44: Extra
characters after interpolation expression; Expected a closing brace to end the
interpolation expression, but found extra characters..

Error, however if I rename "0_VALUE_FROM_NODE_NAMES" to "FIRST_VALUE_FROM_NODE_NAMES" or "THE_0TH_VALUE_FROM_NODE_NAMES", this works fine, so clearly having numbers at beginning of strings in keys (in a map) is not allowed.

I'm okay with this not being fixed, it's a perfectly acceptable restriction, with a trivial workaround, so long as it is documented in https://www.terraform.io/docs/configuration/functions/templatefile.html or similar. I found no documentation warning on this.

This is very low priority.

Additional Context

I'm using JSON instead of HCL as this is a machine generated file

@andrew-lee-1089
Copy link
Author

Great, thanks!

@ghost
Copy link

ghost commented Apr 1, 2020

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.

@ghost ghost locked and limited conversation to collaborators Apr 1, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug documentation v0.12 Issues (primarily bugs) reported against v0.12 releases
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants