Unable to Escape Interpolation inside Variable

2,382 views
Skip to first unread message

Ethan Edwards

unread,
Apr 26, 2016, 1:49:42 PM4/26/16
to Terraform
I'm extremely frustrated because this very simple task appears impossible.

I have some variables with a default value that contains the characters ${} inside them. This is causing Terraform to think I'm trying to use interpolation in a variable.

According to the documentation, I should be able to escape the ${} by just doubling the dollar sign ($$). However, this also fails, as terraform then reports it as an 'illegal char escape'.

variable "nlog_filelog_target_layout" {
type = "string"
default = "${longdate}|${level:uppercase=true}|${logger}|${message}|${exception:format=ToString,StackTrace}${newline}"
}

Is this a bug? Is Terraform unable to escape ${} when it's inside a variable's default value?

I'm using 0.6.15

Paul Hinze

unread,
Apr 26, 2016, 1:56:13 PM4/26/16
to terrafo...@googlegroups.com
Hi Ethan,

Variable defaults do not currently support any interpolation, so the raw contents of the default should pass through just fine and not require escaping.

So for example:

variable "nlog_filelog_target_layout" {
  type    = "string"
  default = "${longdate}|${level:uppercase=true}|${logger}|${message}|${exception:format=ToString,StackTrace}${newline}"
}

output "got" {
  value = "${var.nlog_filelog_target_layout}"
}

Yields:

Outputs:

got = ${longdate}|${level:uppercase=true}|${logger}|${message}|${exception:format=ToString,StackTrace}${newline}


I hope this helps! Let me know if I'm missing any detail here.

Paul

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/hashicorp/terraform/issues
IRC: #terraform-tool on Freenode
---
You received this message because you are subscribed to the Google Groups "Terraform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to terraform-too...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/terraform-tool/47dde847-7eb4-42b0-b046-ffe4ae59a61a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ethan Edwards

unread,
Apr 26, 2016, 2:05:21 PM4/26/16
to Terraform
Hi Paul,

Thanks so much for the fast response.

Somehow I did manage to get Terraform to stop complaining about the following two blocks:

variable "nlog_console_target_layout" {
type = "string"
default = "${date:format=MM/dd HH\\:mm\\:ss} ${logger}|${message}"
}

variable "nlog_filelog_target_layout" {
type = "string"
default = "${longdate}|${level:uppercase=true}|${logger}|${message}|${exception:format=ToString,StackTrace}${newline}"
}

However, the following block is continuing to give me an error:

variable "nlog_filelog_target_fileName" {
type = "string"
default = "DiscoWorker.${level}.log"
}


$ terraform validate

Error validating: 1 error(s) occurred:


* Variable 'nlog_filelog_target_fileName': cannot contain interpolations


Any suggestions?

Thanks,
-Ethan

Ethan Edwards

unread,
Apr 26, 2016, 2:33:55 PM4/26/16
to Terraform
Another follow-up, it appears that interpolation is definitely NOT being ignored for default values.

Not only is the above not working, but I had to remove the escaping I added to the following block, as while the escaping keeps terraform from giving a syntax error, I still end up with the raw values in my field:

variable "nlog_console_target_layout" {
type = "string"
default = "${date:format=MM/dd HH\\:mm\\:ss} ${logger}|${message}"
}

If I take out the backslashes in HH\\:mm\\:ss (e.g. HH\:mm\:ss), terraform gives an error:

At 65:40: illegal char escape


I need that exact value as is, "HH\:mm\:ss", but escaping it causes the extra backslashes to appear in the consul key that I'm storing the value in.

Blargh!

-Ethan

Ethan Edwards

unread,
Apr 26, 2016, 2:38:50 PM4/26/16
to Terraform
As a temporary workaround I tried moving it into a vars file instead (making the variable required).

Same issue:

$ terraform plan -var-file=vars.tfvars consul_nlog_config-v0.0.7


invalid value "vars.tfvars" for flag -var-file: Error parsing vars.tfvars: At 14:58: illegal char escape


If I double the backslashes, then I end up with double backslashes in consul.

Paul Hinze

unread,
Apr 26, 2016, 2:52:41 PM4/26/16
to terrafo...@googlegroups.com
Oy! This is starting to sound like a bug now.

Think you could file a GitHub issue to the effect of "unable to set consul key with backslash from input variable"?

I believe using an environment variable to input the problematic variable might be a valid workaround:

export TF_VAR_nlog_console_target_layout='${date:format=MM/dd HH\:mm\:ss} ${logger}|${message}'

Ethan Edwards

unread,
Apr 26, 2016, 3:10:36 PM4/26/16
to Terraform
Sure, but what about the interpolation issue regarding the ${} syntax, as well?

Would that be a separate github issue?

Paul Hinze

unread,
Apr 26, 2016, 3:21:36 PM4/26/16
to terrafo...@googlegroups.com
However you want to separate it is AOK - once we get the info in GitHub we can merge/split as necessary.

Ethan Edwards

unread,
Apr 26, 2016, 3:58:59 PM4/26/16
to Terraform
Thanks Hinze,

I've opened https://github.com/hashicorp/terraform/issues/6359 - It's a little messy, but hopefully it helps.

Thanks again,
-Ethan

Ethan Edwards

unread,
May 20, 2016, 2:42:25 PM5/20/16
to Terraform
Bumping this since I'm curious if anyone else is getting bitten by these underlying interpolation \ escape issues?

I've proven out the severity of the bug on the issue, but it's gotten zero traction, and I'm surprised since this breaks core terraform functionality.

Has anyone else been bit by these escaping issues? How are you getting around it?
Reply all
Reply to author
Forward
0 new messages