2016-11-13 07:50:28 +01:00
|
|
|
---
|
2020-08-15 03:51:06 +02:00
|
|
|
layout: "language"
|
2018-12-20 05:34:34 +01:00
|
|
|
page_title: "Terraform Settings - Configuration Language"
|
2016-11-13 07:50:28 +01:00
|
|
|
sidebar_current: "docs-config-terraform"
|
|
|
|
description: |-
|
2018-05-14 00:12:49 +02:00
|
|
|
The "terraform" configuration section is used to configure some behaviors
|
|
|
|
of Terraform itself.
|
2016-11-13 07:50:28 +01:00
|
|
|
---
|
|
|
|
|
2018-05-14 00:12:49 +02:00
|
|
|
# Terraform Settings
|
2016-11-13 07:50:28 +01:00
|
|
|
|
2018-05-14 00:12:49 +02:00
|
|
|
The special `terraform` configuration block type is used to configure some
|
|
|
|
behaviors of Terraform itself, such as requiring a minimum Terraform version to
|
|
|
|
apply your configuration.
|
2016-11-13 07:50:28 +01:00
|
|
|
|
2018-05-14 00:12:49 +02:00
|
|
|
## Terraform Block Syntax
|
2016-11-13 07:50:28 +01:00
|
|
|
|
2020-03-23 19:00:11 +01:00
|
|
|
Terraform settings are gathered together into `terraform` blocks:
|
2016-11-13 07:50:28 +01:00
|
|
|
|
2017-04-05 17:29:27 +02:00
|
|
|
```hcl
|
2016-11-13 07:50:28 +01:00
|
|
|
terraform {
|
2018-05-14 00:12:49 +02:00
|
|
|
# ...
|
2016-11-13 07:50:28 +01:00
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2018-05-14 00:12:49 +02:00
|
|
|
Each `terraform` block can contain a number of settings related to Terraform's
|
|
|
|
behavior. Within a `terraform` block, only constant values can be used;
|
|
|
|
arguments may not refer to named objects such as resources, input variables,
|
|
|
|
etc, and may not use any of the Terraform language built-in functions.
|
|
|
|
|
|
|
|
The various options supported within a `terraform` block are described in the
|
|
|
|
following sections.
|
2016-11-13 07:50:28 +01:00
|
|
|
|
2018-05-14 00:12:49 +02:00
|
|
|
## Configuring a Terraform Backend
|
2016-11-13 07:50:28 +01:00
|
|
|
|
2020-03-23 19:00:11 +01:00
|
|
|
The nested `backend` block configures which backend Terraform should use.
|
2017-05-29 07:58:08 +02:00
|
|
|
|
2020-03-23 19:00:11 +01:00
|
|
|
The syntax and behavior of the `backend` block is described in [Backend
|
2021-01-15 23:13:53 +01:00
|
|
|
Configuration](/docs/language/settings/backends/configuration.html).
|
2016-11-13 07:50:28 +01:00
|
|
|
|
|
|
|
## Specifying a Required Terraform Version
|
|
|
|
|
2020-03-23 19:00:11 +01:00
|
|
|
The `required_version` setting accepts a [version constraint
|
2021-01-15 23:13:53 +01:00
|
|
|
string,](/docs/language/expressions/version-constraints.html) which specifies which versions of Terraform
|
2020-03-23 19:00:11 +01:00
|
|
|
can be used with your configuration.
|
2016-11-13 07:50:28 +01:00
|
|
|
|
2020-03-23 19:00:11 +01:00
|
|
|
If the running version of Terraform doesn't match the constraints specified,
|
|
|
|
Terraform will produce an error and exit without taking any further actions.
|
|
|
|
|
2021-01-15 23:13:53 +01:00
|
|
|
When you use [child modules](/docs/language/modules/index.html), each module can specify its own
|
2020-03-23 19:00:11 +01:00
|
|
|
version requirements. The requirements of all modules in the tree must be
|
|
|
|
satisfied.
|
2016-11-13 07:50:28 +01:00
|
|
|
|
2018-12-11 01:14:33 +01:00
|
|
|
Use Terraform version constraints in a collaborative environment to
|
2019-05-20 23:37:03 +02:00
|
|
|
ensure that everyone is using a specific Terraform version, or using at least
|
2018-05-14 00:12:49 +02:00
|
|
|
a minimum Terraform version that has behavior expected by the configuration.
|
2016-11-13 07:50:28 +01:00
|
|
|
|
2018-12-11 01:14:33 +01:00
|
|
|
The `required_version` setting applies only to the version of Terraform CLI.
|
2020-07-31 06:07:36 +02:00
|
|
|
Terraform's resource types are implemented by provider plugins,
|
|
|
|
whose release cycles are independent of Terraform CLI and of each other.
|
2021-01-15 23:13:53 +01:00
|
|
|
Use [the `required_providers` block](/docs/language/providers/requirements.html) to manage
|
2020-07-31 06:07:36 +02:00
|
|
|
the expected versions for each provider you use.
|
2017-04-05 17:29:27 +02:00
|
|
|
|
2020-03-23 19:00:11 +01:00
|
|
|
## Specifying Provider Requirements
|
2017-04-05 17:29:27 +02:00
|
|
|
|
2020-03-23 19:00:11 +01:00
|
|
|
[inpage-source]: #specifying-provider-requirements
|
2018-05-14 00:12:49 +02:00
|
|
|
|
2020-03-23 19:00:11 +01:00
|
|
|
The `required_providers` block specifies all of the providers required by the
|
2020-07-31 06:07:36 +02:00
|
|
|
current module, mapping each local provider name to a source address and a
|
|
|
|
version constraint.
|
2020-01-14 13:59:18 +01:00
|
|
|
|
|
|
|
```hcl
|
|
|
|
terraform {
|
|
|
|
required_providers {
|
|
|
|
aws = {
|
|
|
|
version = ">= 2.7.0"
|
2020-03-23 19:00:11 +01:00
|
|
|
source = "hashicorp/aws"
|
2020-01-14 13:59:18 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2021-01-15 23:13:53 +01:00
|
|
|
For more information, see [Provider Requirements](/docs/language/providers/requirements.html).
|
2020-03-23 19:00:11 +01:00
|
|
|
|
2020-01-04 02:12:49 +01:00
|
|
|
## Experimental Language Features
|
|
|
|
|
2020-03-23 19:00:11 +01:00
|
|
|
The Terraform team will sometimes introduce new language features initially via
|
|
|
|
an opt-in experiment, so that the community can try the new feature and give
|
|
|
|
feedback on it prior to it becoming a backward-compatibility constraint.
|
2020-01-04 02:12:49 +01:00
|
|
|
|
|
|
|
In releases where experimental features are available, you can enable them on
|
|
|
|
a per-module basis by setting the `experiments` argument inside a `terraform`
|
|
|
|
block:
|
|
|
|
|
|
|
|
```hcl
|
|
|
|
terraform {
|
|
|
|
experiments = [example]
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
The above would opt in to an experiment named `example`, assuming such an
|
|
|
|
experiment were available in the current Terraform version.
|
|
|
|
|
|
|
|
Experiments are subject to arbitrary changes in later releases and, depending on
|
|
|
|
the outcome of the experiment, may change drastically before final release or
|
|
|
|
may not be released in stable form at all. Such breaking changes may appear
|
|
|
|
even in minor and patch releases. We do not recommend using experimental
|
|
|
|
features in Terraform modules intended for production use.
|
|
|
|
|
|
|
|
In order to make that explicit and to avoid module callers inadvertently
|
|
|
|
depending on an experimental feature, any module with experiments enabled will
|
|
|
|
generate a warning on every `terraform plan` or `terraform apply`. If you
|
|
|
|
want to try experimental features in a shared module, we recommend enabling the
|
|
|
|
experiment only in alpha or beta releases of the module.
|
|
|
|
|
|
|
|
The introduction and completion of experiments is reported in
|
|
|
|
[Terraform's changelog](https://github.com/hashicorp/terraform/blob/master/CHANGELOG.md),
|
|
|
|
so you can watch the release notes there to discover which experiment keywords,
|
|
|
|
if any, are available in a particular Terraform release.
|
2020-03-06 01:53:24 +01:00
|
|
|
|
|
|
|
## Passing Metadata to Providers
|
|
|
|
|
|
|
|
The `terraform` block can have a nested `provider_meta` block for each
|
|
|
|
provider a module is using, if the provider defines a schema for it. This
|
2020-03-23 19:00:11 +01:00
|
|
|
allows the provider to receive module-specific information, and is primarily
|
|
|
|
intended for modules distributed by the same vendor as the associated provider.
|
|
|
|
|
|
|
|
For more information, see [Provider Metadata](/docs/internals/provider-meta.html).
|