From 770d62e588c306bf8ed48cfa186bf6e2464bd86e Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 7 Oct 2014 20:15:08 -0700 Subject: [PATCH] website: document path variables --- .../docs/configuration/interpolation.html.md | 6 +++++ .../source/docs/modules/create.html.markdown | 26 +++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/website/source/docs/configuration/interpolation.html.md b/website/source/docs/configuration/interpolation.html.md index 5e43bbd2bd..5679b4ff0a 100644 --- a/website/source/docs/configuration/interpolation.html.md +++ b/website/source/docs/configuration/interpolation.html.md @@ -39,6 +39,12 @@ For example, `${count.index}` will interpolate the current index in a multi-count resource. For more information on count, see the resource configuration page. +**To reference path information**, the syntax is `path.TYPE`. +TYPE can be `cwd`, `module`, or `root`. `cwd` will interpolate the +cwd. `module` will interpolate the path to the current module. `root` +will interpolate the path of the root module. In general, you probably +want the `path.module` variable. + ## Built-in Functions Terraform ships with built-in functions. Functions are called with diff --git a/website/source/docs/modules/create.html.markdown b/website/source/docs/modules/create.html.markdown index ce0a7f1c4f..bfe12395f9 100644 --- a/website/source/docs/modules/create.html.markdown +++ b/website/source/docs/modules/create.html.markdown @@ -79,6 +79,32 @@ And that is all there is to it. Variables and outputs are used to configure modules and provide results. Resources within a module are isolated, and the whole thing is managed as a single unit. +## Paths and Embedded Files + +It is sometimes useful to embed files within the module that aren't +Terraform configuration files, such as a script to provision a resource +or a file to upload. + +In these cases, you can't use a relative path, since paths in Terraform +are generally relative to the working directory that Terraform was executed +from. Instead, you want to use a module-relative path. To do this, use +the [path interpolated variables](/docs/configuration/interpolation.html). + +An example is shown below: + +``` +resource "aws_instance" "server" { + ... + + provisioner "remote-exec" { + script = "${path.module}/script.sh" + } +} +``` + +In the above, we use `${path.module}` to get a module-relative path. This +is usually what you'll want in any case. + ## Nested Modules You can use a module within a module just like you would anywhere else.