github.com/jgadling/terraform@v0.3.8-0.20150227214559-abd68c2c87bc/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 your own resource**, the syntax is 30 `self.ATTRIBUTE`. For example `${self.private_ip_address}` will 31 interpolate that resource's private IP address. Note that this is 32 only allowed/valid within provisioners. 33 34 **To reference attributes of other resources**, the syntax is 35 `TYPE.NAME.ATTRIBUTE`. For example, `${aws_instance.web.id}` 36 will interpolate the ID attribute from the "aws\_instance" 37 resource named "web". If the resource has a `count` attribute set, 38 you can access individual attributes with a zero-based index, such 39 as `${aws_instance.web.0.id}`. You can also use the splat syntax 40 to get a list of all the attributes: `${aws_instance.web.*.id}`. 41 This is documented in more detail in the 42 [resource configuration page](/docs/configuration/resources.html). 43 44 **To reference outputs from a module**, the syntax is 45 `MODULE.NAME.OUTPUT`. For example `${module.foo.bar}` will 46 interpolate the "bar" output from the "foo" 47 [module](/docs/modules/index.html). 48 49 **To reference count information**, the syntax is `count.FIELD`. 50 For example, `${count.index}` will interpolate the current index 51 in a multi-count resource. For more information on count, see the 52 resource configuration page. 53 54 **To reference path information**, the syntax is `path.TYPE`. 55 TYPE can be `cwd`, `module`, or `root`. `cwd` will interpolate the 56 cwd. `module` will interpolate the path to the current module. `root` 57 will interpolate the path of the root module. In general, you probably 58 want the `path.module` variable. 59 60 ## Built-in Functions 61 62 Terraform ships with built-in functions. Functions are called with 63 the syntax `name(arg, arg2, ...)`. For example, 64 to read a file: `${file("path.txt")}`. The built-in functions 65 are documented below. 66 67 The supported built-in functions are: 68 69 * `concat(args...)` - Concatenates the values of multiple arguments into 70 a single string. 71 72 * `file(path)` - Reads the contents of a file into the string. Variables 73 in this file are _not_ interpolated. The contents of the file are 74 read as-is. 75 76 * `join(delim, list)` - Joins the list with the delimiter. A list is 77 only possible with splat variables from resources with a count 78 greater than one. Example: `join(",", aws_instance.foo.*.id)` 79 80 * `split(delim, string)` - Splits the string previously created by `join` 81 back into a list. This is useful for pushing lists through module 82 outputs since they currently only support string values. 83 Example: `split(",", module.amod.server_ids)` 84 85 * `lookup(map, key)` - Performs a dynamic lookup into a mapping 86 variable. The `map` parameter should be another variable, such 87 as `var.amis`. 88 89 * `element(list, index)` - Returns a single element from a list 90 at the given index. If the index is greater than the number of 91 elements, this function will wrap using a standard mod algorithm. 92 A list is only possible with splat variables from resources with 93 a count greater than one. 94 Example: `element(aws_subnet.foo.*.id, count.index)`