Files
opentf/website/source/docs/providers/template/index.html.markdown
George Christou 61277c0dbd website/docs: Run terraform fmt on code examples (#12075)
* docs/vsphere: Fix code block

* docs: Convert `...` to `# ...` to allow `terraform fmt`ing

* docs: Trim trailing whitespace

* docs: First-pass run of `terraform fmt` on code examples
2017-02-19 00:48:50 +02:00

1.2 KiB

layout, page_title, sidebar_current, description
layout page_title sidebar_current description
template Provider: Template docs-template-index The Template provider is used to template strings for other Terraform resources.

Template Provider

The template provider exposes data sources to use templates to generate strings for other Terraform resources or outputs.

Use the navigation to the left to read about the available data sources.

Example Usage

# Template for initial configuration bash script
data "template_file" "init" {
  template = "${file("init.tpl")}"

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

# Create a web server
resource "aws_instance" "web" {
  # ...

  user_data = "${data.template_file.init.rendered}"
}

Or using an inline template:

# Template for initial configuration bash script
data "template_file" "init" {
  template = "$${consul_address}:1234"

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

# Create a web server
resource "aws_instance" "web" {
  # ...

  user_data = "${data.template_file.init.rendered}"
}

-> Note: Inline templates must escape their interpolations (as seen by the double $ above). Unescaped interpolations will be processed before the template.