Description
Terraform Version
Terraform v1.5.2
on windows_amd64
Terraform Configuration Files
Terraform is able to select a pre-release provider for a module even if it's explicitly denied using a version constraint.
This means that if any one module enforces a pre-release version and other modules use pessimistic or greater than version constraints, after all the constraints are AND'ed together, a pre-release version will be selected.
terraform {
required_providers {
myprovider= {
source = "mydomain.com/namespace/myprovider"
version = "~>2.0, !=2.0.1-alpha1, !=2.0.1-alpha2"
}
}
}
output
### Debug Output
$ terraform init -upgrade
Initializing the backend...
Upgrading modules...
- my-module in ....\modules\terraform-myprovider-my-module
Initializing provider plugins...
- Finding mydomain.com/namespace/myprovider versions matching ""~> 2.0, !=2.0.1-alpha1, != 2.0.1-alpha2, 2.0.1-alpha2"...
- Installing mydomain.com/namespace/myprovider v2.0.1-alpha2...
- Installed mydomain.com/namespace/myprovider v2.0.1-alpha2 (unauthenticated)
Terraform has created a lock file .terraform.lock.hcl to record the provider
selections it made above. Include this file in your version control repository
so that Terraform can guarantee to make the same selections by default when
you run "terraform init" in the future.
### Expected Behavior
We expected that we should be able to deny a specific pre-release version of a provider in the provider version constraint in our modules. In the case where we combine a module that explicitly requires a pre-release provider and another module that explicitly denies this provider, an error is appropriate and expected.
The documentation is ambiguous in this regard as the != "not equals" operator is an "exact" operator but is not listed here:
https://developer.hashicorp.com/terraform/language/expressions/version-constraints
- A prerelease version is a version number that contains a suffix introduced by a dash, like 1.2.0-beta. A prerelease version can be selected only by an exact version constraint (the = operator or no operator). Prerelease versions do not match inexact operators such as >=, ~>, etc.
### Actual Behavior
Terraform selects the pre-release provider despite the constraint to the contrary.
### Steps to Reproduce
1. Have a pre-release provider version available (in this case 2.0.1-alpha1)
2. Define a provider constraint like:
version = "2.0.1-alpha1, !=2.0.1-alpha1"
3. Expect an error as constraint not resolvable.
### Additional Context
_No response_
### References
_No response_