$ terraform --version
Terraform v0.11.7
I would like to annotate template files with comments.
Currently, the parser does not accept multi-line comments within string interpolations:
$ echo '"${ /* comment */ "" }"' | terraform console
parse error at 1:7: expected expression but found "/"
This can be achieved today by writing annotations within a string which is immediately cleared via the built-in replace function:
{
"foo": 23,
${replace("
this is a comment
", "/.*/", "")}
"bar": 45
}
But this is very noisy and potentially confusing.
For instance,
{
"foo": 23,
${/**
* this is a comment
*/"" }
"bar": 45
}
Support for comments within templates was requested in gh-8260, but that was rejected based on the assumption that this would require a new language construct. This approach isn't quite as legible as a dedicated "template comment" syntax (particularly in its use of the empty string), but it also allows for template annotation without a new language construct.
In any event, thanks for the great tool!
I suspect this will already work now that we're using HCL2 rather than HCL1+HIL. The template_file provider is not yet updated (that'll be a separate step from Terraform itself since that provider has its own release rhythm) but it should work for _inline_ templates (that is, interpolations in string literals) in the v0.12.0-alpha4 builds.
I tried your first terraform console example quickly on my latest build from master just to see what would happen:
$ terraform console
> "${ /* comment */ "" }"
>
Once we release an updated template_file using HCL2 it should work there too.
Great news! Thanks
Most helpful comment
I suspect this will already work now that we're using HCL2 rather than HCL1+HIL. The
template_fileprovider is not yet updated (that'll be a separate step from Terraform itself since that provider has its own release rhythm) but it should work for _inline_ templates (that is, interpolations in string literals) in the v0.12.0-alpha4 builds.I tried your first
terraform consoleexample quickly on my latest build from master just to see what would happen:Once we release an updated
template_fileusing HCL2 it should work there too.