Skip to content

Commit 6ced245

Browse files
committed
website: configuration
1 parent a16b24a commit 6ced245

5 files changed

Lines changed: 109 additions & 2 deletions

File tree

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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+
To reference variables, use the `var.` prefix followed by the
18+
variable name. For example, `${var.foo}` will interpolate the
19+
`foo` variable value. If the variable is a mapping, then you
20+
can reference static keys in the map with the syntax
21+
`var.MAP.KEY`. For example, `${var.amis.us-east-1}` would
22+
get the value of the `us-east-1` key within the `amis` variable
23+
that is a mapping.
24+
25+
To reference attributes of other resources, the syntax is
26+
`TYPE.NAME.ATTRIBUTE`. For example, `${aws_instance.web.id}`
27+
will interpolate the ID attribute from the "aws\_instance"
28+
resource named "web".
29+
30+
Finally, Terraform ships with built-in functions. Functions
31+
are called with the syntax `name(arg, arg2, ...)`. For example,
32+
to read a file: `${file("path.txt")}`. The built-in functions
33+
are documented below.
34+
35+
## Built-in Functions
36+
37+
The supported built-in functions are:
38+
39+
* `file(path)` - Reads the contents of a file into the string.
40+
41+
* `lookup(map, key)` - Performs a dynamic lookup into a mapping
42+
variable.

website/source/docs/configuration/load.html.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,13 @@ sidebar_current: "docs-config-load"
88

99
When invoking any command that loads the Terraform configuration,
1010
Terraform loads all configuration files within the directory
11-
specified in alphabetical order. The flies loaded must end in
11+
specified in alphabetical order.
12+
13+
The files loaded must end in
1214
either `.tf` or `.tf.json` to specify the format that is in use.
13-
Otherwise, the files are ignored.
15+
Otherwise, the files are ignored. Multiple file formats can
16+
be present in the same directory; it is okay to have one Terraform
17+
configuration file be Terraform syntax and another be JSON.
1418

1519
[Override](/docs/configuration/override.html)
1620
files are the exception, as they're loaded after all non-override
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
---
2+
layout: "docs"
3+
page_title: "Overrides"
4+
sidebar_current: "docs-config-override"
5+
---
6+
7+
# Overrides
8+
9+
Terraform loads all configuration files within a directory and
10+
appends them together. Terraform also has a concept of _overrides_,
11+
a way to create files that are loaded last and _merged_ into your
12+
configuration, rather than appended.
13+
14+
Overrides have a few use cases:
15+
16+
* Machines (tools) can create overrides to modify Terraform
17+
behavior without having to edit the Terraform configuration
18+
tailored to human readability.
19+
20+
* Temporary modifications can be made to Terraform configurations
21+
without having to modify the configuration itself.
22+
23+
Overrides names must be `override` or end in `_override`, excluding
24+
the extension. Examples of valid override files are `override.tf`,
25+
`override.tf.json`, `temp_override.tf`.
26+
27+
Override files are loaded last in alphabetical order.
28+
29+
Override files can be in Terraform syntax or JSON, just like non-override
30+
Terraform configurations.
31+
32+
## Example
33+
34+
If you have a Terraform configuration `example.tf` with the contents:
35+
36+
```
37+
resource "aws_instance" "web" {
38+
ami = "ami-1234567"
39+
}
40+
```
41+
42+
And you created a file `override.tf` with the contents:
43+
44+
```
45+
resource "aws_instance" "web" {
46+
ami = "foo"
47+
}
48+
```
49+
50+
Then the AMI for the one resource will be replaced with "foo". Note
51+
that the override syntax can be Terraform syntax or JSON. You can
52+
mix and match syntaxes without issue.

website/source/docs/configuration/syntax.html.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ Basic bullet point reference:
4747

4848
* Strings are in double-quotes.
4949

50+
* Strings can interpolate other values using syntax wrapped
51+
in `${}`, such as `${var.foo}`. The full syntax for interpolation
52+
is
53+
[documented here](/docs/configuration/interpolation.html).
54+
5055
* Numbers are assumed to be base 10. If you prefix a number with
5156
`0x`, it is treated as a hexadecimal number.
5257

website/source/layouts/docs.erb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
<a href="/docs/configuration/syntax.html">Configuration Syntax</a>
1818
</li>
1919

20+
<li<%= sidebar_current("docs-config-interpolation") %>>
21+
<a href="/docs/configuration/interpolation.html">Interpolation Syntax</a>
22+
</li>
23+
2024
<li<%= sidebar_current("docs-config-override") %>>
2125
<a href="/docs/configuration/override.html">Overrides</a>
2226
</li>

0 commit comments

Comments
 (0)