github.com/iaas-resource-provision/iaas-rpc@v1.0.7-0.20211021023331-ed21f798c408/website/docs/language/expressions/version-constraints.html.md (about) 1 --- 2 layout: "language" 3 page_title: "Version Constraints - Configuration Language" 4 --- 5 6 # Version Constraints 7 8 Anywhere that Terraform lets you specify a range of acceptable versions for 9 something, it expects a specially formatted string known as a version 10 constraint. Version constraints are used when configuring: 11 12 - [Modules](/docs/language/modules/index.html) 13 - [Provider requirements](/docs/language/providers/requirements.html) 14 - [The `required_version` setting](/docs/language/settings/index.html#specifying-a-required-terraform-version) in the `terraform` block. 15 16 ## Version Constraint Syntax 17 18 Terraform's syntax for version constraints is very similar to the syntax used by 19 other dependency management systems like Bundler and NPM. 20 21 ```hcl 22 version = ">= 1.2.0, < 2.0.0" 23 ``` 24 25 A version constraint is a [string literal](/docs/language/expressions/strings.html) 26 containing one or more conditions, which are separated by commas. 27 28 Each condition consists of an operator and a version number. 29 30 Version numbers should be a series of numbers separated by periods (like 31 `1.2.0`), optionally with a suffix to indicate a beta release. 32 33 The following operators are valid: 34 35 - `=` (or no operator): Allows only one exact version number. Cannot be combined 36 with other conditions. 37 38 - `!=`: Excludes an exact version number. 39 40 - `>`, `>=`, `<`, `<=`: Comparisons against a specified version, allowing 41 versions for which the comparison is true. "Greater-than" requests newer 42 versions, and "less-than" requests older versions. 43 44 - `~>`: Allows only the _rightmost_ version component to increment. For example, 45 to allow new patch releases within a specific minor release, use the full 46 version number: `~> 1.0.4` will allow installation of `1.0.5` and `1.0.10` 47 but not `1.1.0`. This is usually called the pessimistic constraint operator. 48 49 ## Version Constraint Behavior 50 51 A version number that meets every applicable constraint is considered acceptable. 52 53 Terraform consults version constraints to determine whether it has acceptable 54 versions of itself, any required provider plugins, and any required modules. For 55 plugins and modules, it will use the newest installed version that meets the 56 applicable constraints. 57 58 If Terraform doesn't have an acceptable version of a required plugin or module, 59 it will attempt to download the newest version that meets the applicable 60 constraints. 61 62 If Terraform isn't able to obtain acceptable versions of external dependencies, 63 or if it doesn't have an acceptable version of itself, it won't proceed with any 64 plans, applies, or state manipulation actions. 65 66 Both the root module and any child module can constrain the acceptable versions 67 of Terraform and any providers they use. Terraform considers these constraints 68 equal, and will only proceed if all of them can be met. 69 70 A prerelease version is a version number that contains a suffix introduced by 71 a dash, like `1.2.0-beta`. A prerelease version can be selected only by an 72 _exact_ version constraint (the `=` operator or no operator). Prerelease 73 versions do not match inexact operators such as `>=`, `~>`, etc. 74 75 ## Best Practices 76 77 ### Module Versions 78 79 - When depending on third-party modules, require specific versions to ensure 80 that updates only happen when convenient to you. 81 82 - For modules maintained within your organization, specifying version ranges 83 may be appropriate if semantic versioning is used consistently or if there is 84 a well-defined release process that avoids unwanted updates. 85 86 ### Terraform Core and Provider Versions 87 88 - Reusable modules should constrain only their minimum allowed versions of 89 Terraform and providers, such as `>= 0.12.0`. This helps avoid known 90 incompatibilities, while allowing the user of the module flexibility to 91 upgrade to newer versions of Terraform without altering the module. 92 93 - Root modules should use a `~>` constraint to set both a lower and upper bound 94 on versions for each provider they depend on.