What is the Terraform provider version constraint syntax?

Answer

Terraform uses version constraint strings to specify acceptable provider and module versions. Operators: =: exact version only. !=: exclude a version. >, >=, <, <=: comparison operators. ~> (pessimistic constraint operator): allows only the rightmost version component to increment. ~> 5.0 allows 5.0, 5.1, 5.99 but NOT 6.0. ~> 5.0.2 allows 5.0.2, 5.0.3 but NOT 5.1.0. Best practices: use ~> major.minor to allow patch updates while pinning the minor version. The .terraform.lock.hcl file (committed to Git) locks exact provider versions — ensuring all team members and CI use the same provider version even if the constraint allows a range. Run terraform init -upgrade to update locked versions within constraints.