Multi line string in variable

3,083 views
Skip to first unread message

Dean Song

unread,
Aug 5, 2014, 9:35:43 PM8/5/14
to terrafo...@googlegroups.com
Hi,

Newbee on Terraform.

Any guide on how to use/store the multi line string in variable in Terraform's var file terraform.tfvars? We're trying to do some test in AWS with Terraform, like "aws_launch_configuration" with a multiline string "user_data".

Or we have to use the json format for the Terraform template?


Sample:
user_data
#description
{
   a: ${var.a}
   b: ${var.b}
}


Thanks,
Dean


Mitchell Hashimoto

unread,
Aug 5, 2014, 11:42:55 PM8/5/14
to Dean Song, terrafo...@googlegroups.com
Dean,

Do lines spanning multiple newlines not work? They should work. If
not, they'll certainly work in Terraform 0.2 (our new grammar we wrote
accepts them).

Another option is to put that data out in a separate file and use the
`file` function.

Best,
Mitchell
> --
> 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 post to this group, send email to terrafo...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/terraform-tool/3b593f05-1ccb-47bf-b9ff-e5a80d128c20%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Dean Song

unread,
Aug 6, 2014, 1:49:54 AM8/6/14
to terrafo...@googlegroups.com, dean.s...@gmail.com
Thanks Mitchell. 

After upgrade to latest 0.1.1 and with the "file" function, I can get the multi line content to the "user_data" var, but seems it didn't get the right value for the variables in the file, like it's still ${var.a}, but not the true value of "a"?

user_data:         "" => "#description\n{\n   a: ${var.a}\n   b: ${var.b}\n}\n"

Thanks,
Dean

Mitchell Hashimoto

unread,
Aug 10, 2014, 12:55:00 PM8/10/14
to Dean Song, terrafo...@googlegroups.com
Dean,

The `file()` function doesn't currently interpolate. We'll be added an
interpolate() function probably to do this.

Best,
Mitchell
> https://groups.google.com/d/msgid/terraform-tool/9fd1d0f5-8c95-4919-b1ad-9681105ea5f2%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages