What ~> actually allows
The pessimistic operator lets only the right-most number you wrote increase. Providers and modules are evaluated by two different libraries, and they differ when you give a single number:
| Constraint | Provider versions | Module versions and required_version |
|---|---|---|
~> 1.2.3 | >= 1.2.3, < 1.3.0 | >= 1.2.3, < 1.3.0 |
~> 1.2 | >= 1.2.0, < 2.0.0 | >= 1.2, < 2.0 |
~> 1 | >= 1.0.0, < 2.0.0 | >= 1 — no upper bound |
~> 0.12 | >= 0.12.0, < 1.0.0 | >= 0.12, < 1.0 |
1.2 | exactly 1.2.0 | exactly 1.2.0 |
Which rules apply where
- Provider: the
versionargument insiderequired_providers. Evaluated with apparentlymart/go-versions. - Module version: the
versionargument of amoduleblock that uses a registry source. Evaluated with hashicorp/go-version, plus Terraform's own pre-release rule. - required_version: the
terraformblock's Terraform CLI version. Also hashicorp/go-version.
Pre-releases
- Providers: a pre-release is only selected when you name it exactly, as in
= 6.0.0-beta1.>= 6.0.0-beta1selects no pre-releases at all. - Modules: a pre-release is only used when the whole constraint is that exact version, written as
1.3.0-beta1or=1.3.0-beta1with no space after the=. - required_version: pre-release constraints are an error. A pre-release Terraform build is checked by its version core, so 1.10.0-beta1 counts as 1.10.0.
Syntax gotchas
- Separate constraints with commas:
>= 1.0, < 2.0. Leaving out the comma is an error. - A missing number counts as zero, so
= 1.2means exactly 1.2.0. - Provider constraints allow at most one space after the operator and no
vprefix. ^and~are not Terraform operators. They belong to npm and Cargo.
OpenTofu
OpenTofu forked Terraform and depends on the same two libraries, so the provider and required_version results apply to OpenTofu too. OpenTofu changed some of its module pre-release handling, so for module pre-releases this tool reflects Terraform's behavior.
About this tester
The engines are TypeScript ports of hashicorp/go-version 1.9.0, apparentlymart/go-versions 1.0.3 and the Terraform code that connects them. They are tested against results from the real Go libraries for 58 constraints × 34 versions, including error messages. Everything runs in your browser.