/compat/terraform/terraform-version-constraints
Terraform version constraints: ~>, >=, != and required_version
verified onenvironmentlocal · windows 10.0.26200 arm64 · GNU bash 5.3.15 (Git Bash) · Terraform v1.16.6updated 2026-10-20
- tool
- Terraform
- versions
- Terraform 1.x, OpenTofu 1.x
- os
- any
Terraform uses the same constraint syntax for required_version (the Terraform CLI) and for provider and module versions. The operator that surprises people is ~>, the pessimistic constraint: it allows only the rightmost version part to increase. ~> 1.15 means >= 1.15, < 2.0; ~> 1.15.0 means >= 1.15.0, < 1.16.0.
Operators
| Constraint | Allows |
|---|---|
| = 1.16.6 (or 1.16.6) | exactly that version |
| != 1.16.6 | anything except that version |
| >= 1.5 | 1.5 and newer, including 2.x |
| >= 1.5, < 2.0 | a range, comma means AND |
| ~> 1.15 | >= 1.15 and < 2.0 |
| ~> 1.15.0 | >= 1.15.0 and < 1.16.0 |
| ~> 6.0 (provider) | >= 6.0 and < 7.0: any 6.x release |
Tested against Terraform 1.16.6
terraform version | head -1
for c in "~> 1.16.0" "~> 1.16" "~> 1.15" "~> 1.15.0" ">= 1.5, < 2.0" "= 1.15.0" "!= 1.16.6" "~> 2.0"; do
printf 'terraform {\n required_version = "%s"\n}\n' "$c" > versions.tf
if terraform validate -no-color >/dev/null 2>&1; then r=allowed; else r=rejected; fi
printf '%-16s %s\n' "$c" "$r"
doneOutput
Terraform v1.16.6 ~> 1.16.0 allowed ~> 1.16 allowed ~> 1.15 allowed ~> 1.15.0 rejected >= 1.5, < 2.0 allowed = 1.15.0 rejected != 1.16.6 rejected ~> 2.0 rejected
When the running version does not match, every command stops with Error: Unsupported Terraform Core version.
Recommendations
- Root modules: pin providers with
~> MAJOR.MINORand commit.terraform.lock.hcl, which records the exact versions and checksums. - Reusable modules: set only a lower bound (
>= 1.5) for Terraform and providers, so callers can upgrade. - Pre-releases such as
1.17.0-beta1match only an exact=constraint.
Sources
Related pages
changes · terraformTerraform 1.5 to 1.16: import, removed and check blocks, and what else changedConfig-driven refactoring came after Terraform 1.4: import and check blocks in 1.5, terraform test in 1.6, removed blocks in 1.7, ephemeral values in 1.10.compat · semverVersion range syntax: ^ and ~ in npm, Cargo, Composer and pipCaret and tilde differ by ecosystem: npm and Composer support ^ and ~, Cargo reads a bare version as a caret range, pip uses ~= from PEP 440. Side by side.errors · terraformTerraform: Error: Unsupported argument. An argument named "x" is not expected hereTerraform fails with Unsupported argument, An argument named "name" is not expected here, when a block sets an attribute its resource or module lacks.