diff --git a/internal/cloud/backend.go b/internal/cloud/backend.go index 7ae10b8cb..90bce8fb6 100644 --- a/internal/cloud/backend.go +++ b/internal/cloud/backend.go @@ -838,10 +838,13 @@ func (b *Cloud) VerifyWorkspaceTerraformVersion(workspaceName string) tfdiags.Di return diags } - // If the workspace has a literal Terraform version, see if we can use a - // looser version constraint. 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")) v120 := version.Must(version.NewSemver("1.2.0")) @@ -883,7 +886,7 @@ func (b *Cloud) VerifyWorkspaceTerraformVersion(workspaceName string) tfdiags.Di tfversion.String(), b.organization, workspace.Name, - workspace.TerraformVersion, + remoteConstraint, ) diags = diags.Append(incompatibleWorkspaceTerraformVersion(message, b.ignoreVersionConflict)) return diags diff --git a/internal/cloud/backend_test.go b/internal/cloud/backend_test.go index 87f7a91f2..3bb9e148d 100644 --- a/internal/cloud/backend_test.go +++ b/internal/cloud/backend_test.go @@ -701,6 +701,7 @@ func TestCloud_VerifyWorkspaceTerraformVersion(t *testing.T) { // pre-release versions are comparable within their pre-release stage (dev, // alpha, beta), but not comparable to different stages and not comparable // 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", "~> 1.1.0-beta", true, true}, {"1.1.0-beta1", "~> 1.1.0-dev", true, true},