terraform/website/source/docs/providers/template/r/dir.html.md

1.6 KiB

layout page_title sidebar_current description
template Template: template_dir docs-template-resource-dir Renders templates from a directory.

template_dir

Renders templates from a directory.

Example Usage

data "template_directory" "init" {
  source_dir      = "${path.cwd}/templates"
  destination_dir = "${path.cwd}/templates.generated"
  
  vars {
    consul_address = "${aws_instance.consul.private_ip}"
  }
}

Argument Reference

The following arguments are supported:

  • source_path - (Required) Path to the directory where the files to template reside.

  • destination_path - (Required) Path to the directory where the templated files will be written.

  • vars - (Optional) Variables for interpolation within the template. Note that variables must all be primitives. Direct references to lists or maps will cause a validation error.

NOTE: Any required parent directories are created automatically. Additionally, any external modification to either the files in the source or destination directories will trigger the resource to be re-created.

Template Syntax

The syntax of the template files is the same as standard interpolation syntax, but you only have access to the variables defined in the vars section.

To access interpolations that are normally available to Terraform configuration (such as other variables, resource attributes, module outputs, etc.) you'll have to expose them via vars as shown below:

resource "template_dir" "init" {
  # ...

  vars {
    foo  = "${var.foo}"
    attr = "${aws_instance.foo.private_ip}"
  }
}