cloud: Fix prerelease version constraint checks

This commit is contained in:
Alisdair McDiarmid 2021-11-01 11:12:58 -04:00
parent 3cd6c0be7a
commit a61bd8a96b
2 changed files with 8 additions and 4 deletions

View File

@ -838,10 +838,13 @@ func (b *Cloud) VerifyWorkspaceTerraformVersion(workspaceName string) tfdiags.Di
return diags return diags
} }
// If the workspace has a literal Terraform version, see if we can use a
// looser version constraint.
remoteVersion, _ := version.NewSemver(workspace.TerraformVersion) remoteVersion, _ := version.NewSemver(workspace.TerraformVersion)
if remoteVersion != nil {
// We can use a looser version constraint if the workspace specifies a
// literal Terraform version, and it is not a prerelease. The latter
// restriction is because we cannot compare prerelease versions with any
// operator other than simple equality.
if remoteVersion != nil && remoteVersion.Prerelease() == "" {
v014 := version.Must(version.NewSemver("0.14.0")) v014 := version.Must(version.NewSemver("0.14.0"))
v120 := version.Must(version.NewSemver("1.2.0")) v120 := version.Must(version.NewSemver("1.2.0"))
@ -883,7 +886,7 @@ func (b *Cloud) VerifyWorkspaceTerraformVersion(workspaceName string) tfdiags.Di
tfversion.String(), tfversion.String(),
b.organization, b.organization,
workspace.Name, workspace.Name,
workspace.TerraformVersion, remoteConstraint,
) )
diags = diags.Append(incompatibleWorkspaceTerraformVersion(message, b.ignoreVersionConflict)) diags = diags.Append(incompatibleWorkspaceTerraformVersion(message, b.ignoreVersionConflict))
return diags return diags

View File

@ -701,6 +701,7 @@ func TestCloud_VerifyWorkspaceTerraformVersion(t *testing.T) {
// pre-release versions are comparable within their pre-release stage (dev, // pre-release versions are comparable within their pre-release stage (dev,
// alpha, beta), but not comparable to different stages and not comparable // alpha, beta), but not comparable to different stages and not comparable
// to final releases. // to final releases.
{"1.1.0-beta1", "1.1.0-beta1", true, false},
{"1.1.0-beta1", "~> 1.1.0-beta", true, false}, {"1.1.0-beta1", "~> 1.1.0-beta", true, false},
{"1.1.0", "~> 1.1.0-beta", true, true}, {"1.1.0", "~> 1.1.0-beta", true, true},
{"1.1.0-beta1", "~> 1.1.0-dev", true, true}, {"1.1.0-beta1", "~> 1.1.0-dev", true, true},