mirror of https://github.com/hashicorp/terraform
parent
a16b24ab4a
commit
6ced245898
@ -0,0 +1,42 @@
|
||||
---
|
||||
layout: "docs"
|
||||
page_title: "Interpolation Syntax"
|
||||
sidebar_current: "docs-config-interpolation"
|
||||
---
|
||||
|
||||
# Interpolation Syntax
|
||||
|
||||
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}`.
|
||||
|
||||
The interpolation syntax is powerful and allows you to reference
|
||||
variables, attributes of resources, call functions, etc.
|
||||
|
||||
To reference variables, use the `var.` prefix followed by the
|
||||
variable name. For example, `${var.foo}` will interpolate the
|
||||
`foo` variable value. If the variable is a mapping, then you
|
||||
can reference static keys in the map with the syntax
|
||||
`var.MAP.KEY`. For example, `${var.amis.us-east-1}` would
|
||||
get the value of the `us-east-1` key within the `amis` variable
|
||||
that is a mapping.
|
||||
|
||||
To reference attributes of other resources, the syntax is
|
||||
`TYPE.NAME.ATTRIBUTE`. For example, `${aws_instance.web.id}`
|
||||
will interpolate the ID attribute from the "aws\_instance"
|
||||
resource named "web".
|
||||
|
||||
Finally, Terraform ships with built-in functions. Functions
|
||||
are called with the syntax `name(arg, arg2, ...)`. For example,
|
||||
to read a file: `${file("path.txt")}`. The built-in functions
|
||||
are documented below.
|
||||
|
||||
## Built-in Functions
|
||||
|
||||
The supported built-in functions are:
|
||||
|
||||
* `file(path)` - Reads the contents of a file into the string.
|
||||
|
||||
* `lookup(map, key)` - Performs a dynamic lookup into a mapping
|
||||
variable.
|
||||
@ -0,0 +1,52 @@
|
||||
---
|
||||
layout: "docs"
|
||||
page_title: "Overrides"
|
||||
sidebar_current: "docs-config-override"
|
||||
---
|
||||
|
||||
# Overrides
|
||||
|
||||
Terraform loads all configuration files within a directory and
|
||||
appends them together. Terraform also has a concept of _overrides_,
|
||||
a way to create files that are loaded last and _merged_ into your
|
||||
configuration, rather than appended.
|
||||
|
||||
Overrides have a few use cases:
|
||||
|
||||
* Machines (tools) can create overrides to modify Terraform
|
||||
behavior without having to edit the Terraform configuration
|
||||
tailored to human readability.
|
||||
|
||||
* Temporary modifications can be made to Terraform configurations
|
||||
without having to modify the configuration itself.
|
||||
|
||||
Overrides names must be `override` or end in `_override`, excluding
|
||||
the extension. Examples of valid override files are `override.tf`,
|
||||
`override.tf.json`, `temp_override.tf`.
|
||||
|
||||
Override files are loaded last in alphabetical order.
|
||||
|
||||
Override files can be in Terraform syntax or JSON, just like non-override
|
||||
Terraform configurations.
|
||||
|
||||
## Example
|
||||
|
||||
If you have a Terraform configuration `example.tf` with the contents:
|
||||
|
||||
```
|
||||
resource "aws_instance" "web" {
|
||||
ami = "ami-1234567"
|
||||
}
|
||||
```
|
||||
|
||||
And you created a file `override.tf` with the contents:
|
||||
|
||||
```
|
||||
resource "aws_instance" "web" {
|
||||
ami = "foo"
|
||||
}
|
||||
```
|
||||
|
||||
Then the AMI for the one resource will be replaced with "foo". Note
|
||||
that the override syntax can be Terraform syntax or JSON. You can
|
||||
mix and match syntaxes without issue.
|
||||
Loading…
Reference in new issue