<commit_before>---
layout: "template"
page_title: "Template: template_file"
sidebar_current: "docs-template-datasource-file"
description: |-
  Renders a template from a file.
---

# template\_file

Renders a template from a file.

## Example Usage

From a file:

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

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

Inline:

```
data "template_file" "init" {
    template = "$${consul_address}:1234"

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

## Argument Reference

The following arguments are supported:

* `template` - (Required) The contents of the template. These can be loaded
  from a file on disk using the [`file()` interpolation
  function](/docs/configuration/interpolation.html#file_path_).
<commit_msg>Added example of variable reference inside file (#11097)<commit_after>---
layout: "template"
page_title: "Template: template_file"
sidebar_current: "docs-template-datasource-file"
description: |-
  Renders a template from a file.
---

# template\_file

Renders a template from a file.

## Example Usage

Option 1: From a file:

Reference the template path:

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

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

Inside the file, reference the variable as such:

```
#!/bin/bash

echo "CONSUL_ADDRESS = ${consul_address}" > /tmp/iplist
```

Option 2: Inline:

```
data "template_file" "init" {
    template = "$${consul_address}:1234"

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

## Argument Reference

The following arguments are supported:

* `template` - (Required) The contents of the template. These can be loaded
  from a file on disk using the [`file()` interpolation
  function](/docs/configuration/interpolation.html#file_path_).

{'fraction_non_alphanumeric': 0.1403953370501774, 'fraction_numerical': 0.007602635580334516, 'mean_word_length': 3.9226932668329177, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2270852', 'n_tokens_mistral': 656, 'n_tokens_neox': 623, 'n_words': 172}