Skip to content

/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

ConstraintAllows
= 1.16.6 (or 1.16.6)exactly that version
!= 1.16.6anything except that version
>= 1.51.5 and newer, including 2.x
>= 1.5, < 2.0a 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

bash
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"
done

Output

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.MINOR and 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-beta1 match only an exact = constraint.

Sources