Closed dpetzel closed 8 years ago
This is correct, I've tagged as an enhancement.
You don't need to left-align all data. The -
only affects the end marker, so you can remove it and put USER_DATA
on the very left. Still not pretty, but it works.
In fact, I don't think -
in any language ignores the leading tabs on the data in the heredoc, just the end marker. At the very least, Ruby is this way, but I tend to remember that being the case universally.
Indeed you are correct, the -
seems to have no effect on that data
in Ruby, it just allows you to not have to indent the end_marker. So in the case of instance user_data, I'm actually not sure this enhancement would even help then, since the I believe the user_data needs to not have the tabs (at least in the context of #cloud-config
).
In fact, I don't think - in any language ignores the leading tabs on the data in the heredoc, just the end marker. At the very least, Ruby is this way, but I tend to remember that being the case universally.
It's not quite universal. In BASH at least the leading tabs on the data are ignored when you use a -
after the <<
Try it yourself. To type a tab use ctrl+v
tab
$ cat <<-EOF
> this
> that
> the other
> EOF
this
that
the other
$ cat <<-EOF
> this
> that
> the other
> EOF
this
that
the other
$ cat <<EOF
> this
> that
> the other
> EOF
this
that
the other
I'd love it if you aim for the bash-like behavior because there are times (like with json policy documents on aws) when you can't have leading whitespace. In fact, taking a page out of the YAML book, it would make me happiest (being a space-indenter) to have the leading (spaces or tabs) indent (of the first line) stripped from every line of the data.
Right now I have to use this:
resource "aws_iam_group_policy" "asset_managers_policy" {
name = "asset_managers_policy"
group = "${aws_iam_group.asset_managers.id}"
policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:*"
],
"Resource": [
"${aws_s3_bucket.assets_bucket.arn}"
]
}
]
}
EOF
}
We can probably agree that everyone would rather read this:
resource "aws_iam_group_policy" "asset_managers_policy" {
name = "asset_managers_policy"
group = "${aws_iam_group.asset_managers.id}"
policy = <<-EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:*"
],
"Resource": [
"${aws_s3_bucket.assets_bucket.arn}"
]
}
]
}
EOF
}
@Phomias Correct, I'm talking about languages without a "-". I consider that additional syntax that we might add to HCL later but don't support currently.
After reviewing https://github.com/hashicorp/hcl/issues/6, I attempted to implement heredoc for user_data in terraform. I had added the following:
This throws the following error:
Error loading config: Error parsing /my_file.tf: Line 76, column 0: syntax error
It appears hcl is not honoring the
-
as outlined in http://en.wikipedia.org/wiki/Here_document:If I unindent everything and remote the
-
it works OK, but IMO the file becomes much harder to read since all the heredoc data needs to be completely left-aligned.