github.com/rstandt/terraform@v0.12.32-0.20230710220336-b1063613405c/website/docs/configuration/terraform.html.md (about) 1 --- 2 layout: "docs" 3 page_title: "Terraform Settings - Configuration Language" 4 sidebar_current: "docs-config-terraform" 5 description: |- 6 The "terraform" configuration section is used to configure some behaviors 7 of Terraform itself. 8 --- 9 10 # Terraform Settings 11 12 -> **Note:** This page is about Terraform 0.12 and later. For Terraform 0.11 and 13 earlier, see 14 [0.11 Configuration Language: Terraform Settings](../configuration-0-11/terraform.html). 15 16 The special `terraform` configuration block type is used to configure some 17 behaviors of Terraform itself, such as requiring a minimum Terraform version to 18 apply your configuration. 19 20 ## Terraform Block Syntax 21 22 Terraform-specific settings are gathered together into `terraform` blocks: 23 24 ```hcl 25 terraform { 26 # ... 27 } 28 ``` 29 30 Each `terraform` block can contain a number of settings related to Terraform's 31 behavior. Within a `terraform` block, only constant values can be used; 32 arguments may not refer to named objects such as resources, input variables, 33 etc, and may not use any of the Terraform language built-in functions. 34 35 The various options supported within a `terraform` block are described in the 36 following sections. 37 38 ## Configuring a Terraform Backend 39 40 The selected _backend_ for a Terraform configuration defines exactly where 41 and how operations are performed, where [state](/docs/state/index.html) is 42 stored, etc. Most non-trivial Terraform configurations will have a backend 43 configuration that configures a remote backend to allow collaboration within 44 a team. 45 46 A backend configuration is given in a nested `backend` block within a 47 `terraform` block: 48 49 ```hcl 50 terraform { 51 backend "s3" { 52 # (backend-specific settings...) 53 } 54 } 55 ``` 56 57 More information on backend configuration can be found in 58 [the _Backends_ section](/docs/backends/index.html). 59 60 ## Specifying a Required Terraform Version 61 62 The `required_version` setting can be used to constrain which versions of 63 the Terraform CLI can be used with your configuration. If the running version of 64 Terraform doesn't match the constraints specified, Terraform will produce 65 an error and exit without taking any further actions. 66 67 When you use [child modules](./modules.html), each module 68 can specify its own version requirements. The requirements of all modules 69 in the tree must be satisfied. 70 71 Use Terraform version constraints in a collaborative environment to 72 ensure that everyone is using a specific Terraform version, or using at least 73 a minimum Terraform version that has behavior expected by the configuration. 74 75 The `required_version` setting applies only to the version of Terraform CLI. 76 Various behaviors of Terraform are actually implemented by Terraform Providers, 77 which are released on a cycle independent of Terraform CLI and of each other. 78 Use [provider version constraints](./providers.html#provider-versions) 79 to make similar constraints on which provider versions may be used. 80 81 The value for `required_version` is a string containing a comma-separated 82 list of constraints. Each constraint is an operator followed by a version 83 number, such as `> 0.12.0`. The following constraint operators are allowed: 84 85 * `=` (or no operator): exact version equality 86 87 * `!=`: version not equal 88 89 * `>`, `>=`, `<`, `<=`: version comparison, where "greater than" is a larger 90 version number 91 92 * `~>`: pessimistic constraint operator, constraining both the oldest and 93 newest version allowed. For example, `~> 0.9` is equivalent to 94 `>= 0.9, < 1.0`, and `~> 0.8.4`, is equivalent to `>= 0.8.4, < 0.9` 95 96 Re-usable modules should constrain only the minimum allowed version, such 97 as `>= 0.12.0`. This specifies the earliest version that the module is 98 compatible with while leaving the user of the module flexibility to upgrade 99 to newer versions of Terraform without altering the module. 100 101 ## Specifying Required Provider Versions 102 103 The `required_providers` setting is a map specifying a version constraint for 104 each provider required by your configuration. 105 106 ```hcl 107 terraform { 108 required_providers { 109 aws = ">= 2.7.0" 110 } 111 } 112 ``` 113 114 Version constraint strings within the `required_providers` block use the 115 same version constraint syntax as for 116 [the `required_version` argument](#specifying-a-required-terraform-version) 117 described above. 118 119 When a configuration contains multiple version constraints for a single 120 provider -- for example, if you're using multiple modules and each one has 121 its own constraint -- _all_ of the constraints must hold to select a single 122 provider version for the whole configuration. 123 124 Re-usable modules should constrain only the minimum allowed version, such 125 as `>= 1.0.0`. This specifies the earliest version that the module is 126 compatible with while leaving the user of the module flexibility to upgrade 127 to newer versions of the provider without altering the module. 128 129 Root modules should use a `~>` constraint to set both a lower and upper bound 130 on versions for each provider they depend on, as described in 131 [Provider Versions](providers.html#provider-versions). 132 133 An alternate syntax is also supported, but not intended for use at this time. 134 It exists to support future enhancements. 135 136 ```hcl 137 terraform { 138 required_providers { 139 aws = { 140 version = ">= 2.7.0" 141 } 142 } 143 } 144 ``` 145 146 ## Experimental Language Features 147 148 From time to time the Terraform team will introduce new language features 149 initially via an opt-in experiment, so that the community can try the new 150 feature and give feedback on it prior to it becoming a backward-compatibility 151 constraint. 152 153 In releases where experimental features are available, you can enable them on 154 a per-module basis by setting the `experiments` argument inside a `terraform` 155 block: 156 157 ```hcl 158 terraform { 159 experiments = [example] 160 } 161 ``` 162 163 The above would opt in to an experiment named `example`, assuming such an 164 experiment were available in the current Terraform version. 165 166 Experiments are subject to arbitrary changes in later releases and, depending on 167 the outcome of the experiment, may change drastically before final release or 168 may not be released in stable form at all. Such breaking changes may appear 169 even in minor and patch releases. We do not recommend using experimental 170 features in Terraform modules intended for production use. 171 172 In order to make that explicit and to avoid module callers inadvertently 173 depending on an experimental feature, any module with experiments enabled will 174 generate a warning on every `terraform plan` or `terraform apply`. If you 175 want to try experimental features in a shared module, we recommend enabling the 176 experiment only in alpha or beta releases of the module. 177 178 The introduction and completion of experiments is reported in 179 [Terraform's changelog](https://github.com/hashicorp/terraform/blob/master/CHANGELOG.md), 180 so you can watch the release notes there to discover which experiment keywords, 181 if any, are available in a particular Terraform release.