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.
Previous
What is Terraform drift and how do you handle it?
Next
What is the Terraform lifecycle of a resource?
More Terraform / IaC Questions
View all →- Intermediate What is the Terraform state locking mechanism?
- Intermediate How do you handle sensitive values in Terraform?
- Intermediate What are Terraform Provisioners and when should you avoid them?
- Intermediate What is Terraform import?
- Intermediate How do you structure Terraform code for large teams?