Terraform: Data Sources > template_file

template_file renders a template from a file.

Use it with a fileor inline. E.g.


data "template_file" "ec2_policy" {
  template = "${file("policies/ec2_policy.json.tftemplate")}"

  vars {
    ip_address - ${aws_instance.my_instances.private_ip}"

file refers to a file path in the current directory.

and ip_address is set to a value which can be read in the template using ${ip_address}.


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

  vars {
    consul_address = "${aws_instance.consul.private_ip}"

Note: see also Terraform: Data Sources

and https://www.terraform.io/docs/providers/template/d/file.html#

Leave a Reply

Your email address will not be published. Required fields are marked *