Can't Escape Special Characters in -Var with Terraform Plan

2,519 views
Skip to first unread message

Ryan Howard

unread,
Sep 26, 2016, 10:18:02 AM9/26/16
to Terraform
Hi All,
I'm having an issue with terraform, and am currently using version 0.7.2, here's what I'm running into. I'm doing my normal "terraform plan", however I'm adding a variable as input this time. doing something like:

terraform plan -var 'my_var=my_value' 

that works fine, but I can't get it to work with an equal sign on the end, or with a special character at the beginning such as a zero(0), like this:

terraform plan -var 'my_var=0encrypted=' 

Looked into escaping documentation, and nothing seems to work so far. Any hint in the right direction? I tried doing 'my_var=encrypted\=' and that doesn't work. I need to pass some private variables in at run time, and don't want to store these in a file. Is there a good way to escape these non alphabetical chars, or do I need to go another direction entirely?

Thanks!
Ryan

Lowe Schmidt

unread,
Sep 26, 2016, 10:36:59 AM9/26/16
to terrafo...@googlegroups.com
what shell are you using? You most likely need to use " for escaping to work. 
Can you try something like terraform plan -var "'my_var=my_escaped\_value'" 

--
Lowe Schmidt | +46 723 867 157

--
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-tool+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/terraform-tool/a7bc0137-971e-4c90-89ee-2f1a0c39d00e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ryan Howard

unread,
Sep 26, 2016, 11:12:21 AM9/26/16
to Terraform
Thanks for the reply, Lowe. I'm using Powershell 5.1. Below is the cleaned up version of what I'm trying. Still doesn't work though, any thoughts?

Terraform plan -var "'other_client_stuff=myvariablestuff\='"

Note the single quotes enclosed in double quotes.

Thanks!


On Monday, September 26, 2016 at 9:36:59 AM UTC-5, Lowe Schmidt wrote:
what shell are you using? You most likely need to use " for escaping to work. 
Can you try something like terraform plan -var "'my_var=my_escaped\_value'" 

--
Lowe Schmidt | +46 723 867 157

On 26 September 2016 at 16:18, Ryan Howard <ryh...@gmail.com> wrote:
Hi All,
I'm having an issue with terraform, and am currently using version 0.7.2, here's what I'm running into. I'm doing my normal "terraform plan", however I'm adding a variable as input this time. doing something like:

terraform plan -var 'my_var=my_value' 

that works fine, but I can't get it to work with an equal sign on the end, or with a special character at the beginning such as a zero(0), like this:

terraform plan -var 'my_var=0encrypted=' 

Looked into escaping documentation, and nothing seems to work so far. Any hint in the right direction? I tried doing 'my_var=encrypted\=' and that doesn't work. I need to pass some private variables in at run time, and don't want to store these in a file. Is there a good way to escape these non alphabetical chars, or do I need to go another direction entirely?

Thanks!
Ryan

--
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.

Rob Coward

unread,
Sep 27, 2016, 1:41:16 AM9/27/16
to Terraform
Have you tried passing the values in as environment variables ?

TF_VAR_other_client_stuff=myvariablestuff\= terraform plan

Lowe Schmidt

unread,
Sep 27, 2016, 3:33:32 AM9/27/16
to terrafo...@googlegroups.com
My powershell knowledge is very limited, sorry :&

--
Lowe Schmidt | +46 723 867 157

To unsubscribe from this group and stop receiving emails from it, send an email to terraform-tool+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/terraform-tool/859ee343-a4ca-4fd7-8f70-370aeded7f1f%40googlegroups.com.

Ryan Howard

unread,
Sep 29, 2016, 2:04:00 PM9/29/16
to Terraform
Hey Rob, 
I did try that, but it doesn't seem to be supported. My Environment variables aren't being read and it's still asking for the missing variable. Have you done this with the latest version of terraform and it worked for you? Specifically on windows and not linux.

Rob Coward

unread,
Sep 30, 2016, 5:15:03 AM9/30/16
to Terraform
Sorry, that was *nix syntax creeping in - I don't believe windows allows the setting of environment variables in-line in the same way that you can with linux. You certainly can read in environment variables to set values on your terraform variables though.

In a cmd shell, you can do:

set TF_VAR_other_client_stuff=myvariablestuff\=
terraform plan

and terraform will set the value of your other_client_stuff variable from the corresponding environment variable. I use it all the time to hide credentials when demoing terraform provider functionality.

Ryan Howard

unread,
Oct 3, 2016, 12:19:27 PM10/3/16
to Terraform
Thanks Rob, worked beautifully, I just got hung up on a typo!

-Ryan
Reply all
Reply to author
Forward
0 new messages