github.com/bengesoff/terraform@v0.3.1-0.20141018223233-b25a53629922/website/source/docs/configuration/interpolation.html.md (about)

     1  ---
     2  layout: "docs"
     3  page_title: "Interpolation Syntax"
     4  sidebar_current: "docs-config-interpolation"
     5  ---
     6  
     7  # Interpolation Syntax
     8  
     9  Embedded within strings in Terraform, whether you're using the
    10  Terraform syntax or JSON syntax, you can interpolate other values
    11  into strings. These interpolations are wrapped in `${}`, such as
    12  `${var.foo}`.
    13  
    14  The interpolation syntax is powerful and allows you to reference
    15  variables, attributes of resources, call functions, etc.
    16  
    17  ## Available Variables
    18  
    19  **To reference user variables**, use the `var.` prefix followed by the
    20  variable name. For example, `${var.foo}` will interpolate the
    21  `foo` variable value. If the variable is a mapping, then you
    22  can reference static keys in the map with the syntax
    23  `var.MAP.KEY`. For example, `${var.amis.us-east-1}` would
    24  get the value of the `us-east-1` key within the `amis` variable
    25  that is a mapping.
    26  
    27  **To reference attributes of other resources**, the syntax is
    28  `TYPE.NAME.ATTRIBUTE`. For example, `${aws_instance.web.id}`
    29  will interpolate the ID attribute from the "aws\_instance"
    30  resource named "web". If the resource has a `count` attribute set,
    31  you can access individual attributes with a zero-based index, such
    32  as `${aws_instance.web.0.id}`. You can also use the splat syntax
    33  to get a list of all the attributes: `${aws_instance.web.*.id}`.
    34  This is documented in more detail in the
    35  [resource configuration page](/docs/configuration/resources.html).
    36  
    37  **To reference outputs from a module**, the syntax is
    38  `MODULE.NAME.OUTPUT`. For example `${module.foo.bar}` will
    39  interpolate the "bar" output from the "foo"
    40  [module](/docs/modules/index.html).
    41  
    42  **To reference count information**, the syntax is `count.FIELD`.
    43  For example, `${count.index}` will interpolate the current index
    44  in a multi-count resource. For more information on count, see the
    45  resource configuration page.
    46  
    47  **To reference path information**, the syntax is `path.TYPE`.
    48  TYPE can be `cwd`, `module`, or `root`. `cwd` will interpolate the
    49  cwd. `module` will interpolate the path to the current module. `root`
    50  will interpolate the path of the root module. In general, you probably
    51  want the `path.module` variable.
    52  
    53  ## Built-in Functions
    54  
    55  Terraform ships with built-in functions. Functions are called with
    56  the syntax `name(arg, arg2, ...)`. For example,
    57  to read a file: `${file("path.txt")}`. The built-in functions
    58  are documented below.
    59  
    60  The supported built-in functions are:
    61  
    62    * `concat(args...)` - Concatenates the values of multiple arguments into
    63        a single string.
    64  
    65    * `file(path)` - Reads the contents of a file into the string. Variables
    66        in this file are _not_ interpolated. The contents of the file are
    67        read as-is.
    68  
    69    * `join(delim, list)` - Joins the list with the delimiter. A list is
    70        only possible with splat variables from resources with a count
    71        greater than one. Example: `join(",", aws_instance.foo.*.id)`
    72  
    73    * `lookup(map, key)` - Performs a dynamic lookup into a mapping
    74        variable.