github.com/chalford/terraform@v0.3.7-0.20150113080010-a78c69a8c81f/website/source/docs/configuration/interpolation.html.md (about)

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