-
Notifications
You must be signed in to change notification settings - Fork 9.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Indent function in template file failed to render #16775
Comments
Unfortunately this is the expected behavior today: the We have plans in future to make templates a more "first-class" idea in Terraform, rather than a separate provider, and that would allow them to integrate more deeply with Terraform's value scope and interpolation functions. Unfortunately there's a fair amount of work we need to get done before we can do that, since it'll interact with the new version of the configuration language we're integrating currently. In the mean time I think the best way to do this is to inline the "template" inside your config as a local value definition. This is not ideal because it doesn't allow your editor to see the result as YAML, but it allows the use of interpolation functions and avoids the need for defining a separate set of variables: locals {
config_yaml = <<EOT
ca_rsa_private: |
${indent(2, tls_private_key.ca.private_key_pem)}
EOT
} Alternatively, you could exploit the fact that YAML accepts JSON syntax and instead assign this YAML attribute in JSON, at the expense of readability of the resulting YAML file: ca_rsa_private: ${ca_rsa_private_json} data "template_file" "config-yaml" {
template = "${file("${path.module}/config.yaml.tpl")}"
vars {
ca_rsa_private_json = "${jsonencode(tls_private_key.ca.private_key_pem)}"
}
} ...though indeed this isn't really much better than your example of passing in the already-indented string, except that it at least doesn't need to hard-code a specific indentation level and thus decouples the YAML file layout from the Terraform config. |
This issue has been automatically migrated to hashicorp/terraform-provider-template#23 because it looks like an issue with that provider. If you believe this is not an issue with the provider, please reply to this issue and let us know. |
Thanks for the explanation @apparentlymart , but perhaps the doc should be corrected: https://www.terraform.io/docs/configuration/interpolation.html
|
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further. |
Terraform Version
Terraform Configuration Files
config.yaml.tpl:
Expected Behavior
No error
Actual Behavior
Got this error:
Important Factoids
If i use the indent function directly in the TF file, it works fine.
config.yaml.tpl:
The text was updated successfully, but these errors were encountered: