Skip to content
This repository has been archived by the owner on Oct 8, 2020. It is now read-only.

Indent function in template file failed to render #23

Open
hashibot opened this issue Dec 5, 2017 · 1 comment
Open

Indent function in template file failed to render #23

hashibot opened this issue Dec 5, 2017 · 1 comment

Comments

@hashibot
Copy link

hashibot commented Dec 5, 2017

This issue was originally opened by @sebastien-prudhomme as hashicorp/terraform#16775. It was migrated here as a result of the provider split. The original body of the issue is below.


Terraform Version

Terraform v0.11.0 and Terraform v.0.10.8

Terraform Configuration Files

resource "tls_private_key" "ca" {
  algorithm = "RSA"
  rsa_bits  = "2048"
}

data "template_file" "config-yaml" {
  template = "${file("${path.module}/config.yaml.tpl")}"

  vars {
    ca_rsa_private = "${tls_private_key.ca.private_key_pem}"
  }
}

config.yaml.tpl:

ca_rsa_private: |
  ${indent(2, ca_rsa_private)}

Expected Behavior

No error

Actual Behavior

Got this error:

failed to render : 2:5: unknown function called: indent

Important Factoids

If i use the indent function directly in the TF file, it works fine.

data "template_file" "config-yaml" {
  template = "${file("${path.module}/config.yaml.tpl")}"

  vars {
    ca_rsa_private = "${indent(2, tls_private_key.ca.private_key_pem)}"
  }
}

config.yaml.tpl:

ca_rsa_private: |
  ${ca_rsa_private}
@RomanHotsiy
Copy link

Was able to work around this issue using replace, i.e.:

ca_rsa_private: |
  ${indent(2, ca_rsa_private)}

becomes:

ca_rsa_private: |
  ${replace(ca_rsa_private, "\n", "\n  ")} # <-- 2 spaces here

For some reason, replace is available in the template file context while indent is not.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants