Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix >= 0.12.0 version detection for versions with prereleases #1286

Merged
merged 1 commit into from
Dec 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions server/events/runtime/plan_step_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ func (p *PlanStepRunner) buildPlanCmd(ctx models.ProjectCommandContext, extraArg
// actually used in the configuration. Since there's no way for us to detect
// if the configuration is using those variables, we don't set them.
func (p *PlanStepRunner) tfVars(ctx models.ProjectCommandContext, tfVersion *version.Version) []string {
if vTwelveAndUp.Check(tfVersion) {
if tfVersion.GreaterThanOrEqual(version.Must(version.NewVersion("0.12.0"))) {
return nil
}

Expand Down Expand Up @@ -299,8 +299,6 @@ func (p *PlanStepRunner) runRemotePlan(
return output, err
}

var vTwelveAndUp = MustConstraint(">=0.12-a")

// remoteOpsErr01114 is the error terraform plan will return if this project is
// using TFE remote operations in TF 0.11.14.
var remoteOpsErr01114 = `Error: Saving a generated plan is currently not supported!
Expand Down
89 changes: 55 additions & 34 deletions server/events/runtime/plan_step_runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -618,40 +618,9 @@ func TestRun_OutputOnErr(t *testing.T) {
// being used.
func TestRun_NoOptionalVarsIn012(t *testing.T) {
RegisterMockTestingT(t)
terraform := mocks.NewMockClient()

tfVersion, _ := version.NewVersion("0.12.0")
s := runtime.PlanStepRunner{
TerraformExecutor: terraform,
DefaultTFVersion: tfVersion,
}

When(terraform.RunCommandWithVersion(
matchers.AnyPtrToLoggingSimpleLogger(),
AnyString(),
AnyStringSlice(),
matchers2.AnyMapOfStringToString(),
matchers2.AnyPtrToGoVersionVersion(),
AnyString())).ThenReturn("output", nil)

output, err := s.Run(models.ProjectCommandContext{
Workspace: "default",
RepoRelDir: ".",
User: models.User{Username: "username"},
EscapedCommentArgs: []string{"comment", "args"},
Pull: models.PullRequest{
Num: 2,
},
BaseRepo: models.Repo{
FullName: "owner/repo",
Owner: "owner",
Name: "repo",
},
}, []string{"extra", "args"}, "/path", map[string]string(nil))
Ok(t, err)
Equals(t, "output", output)

expPlanArgs := []string{"plan",
expPlanArgs := []string{
"plan",
"-input=false",
"-refresh",
"-no-color",
Expand All @@ -662,7 +631,59 @@ func TestRun_NoOptionalVarsIn012(t *testing.T) {
"comment",
"args",
}
terraform.VerifyWasCalledOnce().RunCommandWithVersion(nil, "/path", expPlanArgs, map[string]string(nil), tfVersion, "default")

cases := []struct {
name string
tfVersion string
}{
{
"stable version",
"0.12.0",
},
{
"with prerelease",
"0.14.0-rc1",
},
}

for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
terraform := mocks.NewMockClient()
When(terraform.RunCommandWithVersion(
matchers.AnyPtrToLoggingSimpleLogger(),
AnyString(),
AnyStringSlice(),
matchers2.AnyMapOfStringToString(),
matchers2.AnyPtrToGoVersionVersion(),
AnyString())).ThenReturn("output", nil)

tfVersion, _ := version.NewVersion(c.tfVersion)
s := runtime.PlanStepRunner{
TerraformExecutor: terraform,
DefaultTFVersion: tfVersion,
}

output, err := s.Run(models.ProjectCommandContext{
Workspace: "default",
RepoRelDir: ".",
User: models.User{Username: "username"},
EscapedCommentArgs: []string{"comment", "args"},
Pull: models.PullRequest{
Num: 2,
},
BaseRepo: models.Repo{
FullName: "owner/repo",
Owner: "owner",
Name: "repo",
},
}, []string{"extra", "args"}, "/path", map[string]string(nil))
Ok(t, err)
Equals(t, "output", output)

terraform.VerifyWasCalledOnce().RunCommandWithVersion(nil, "/path", expPlanArgs, map[string]string(nil), tfVersion, "default")
})
}

}

// Test plans if using remote ops.
Expand Down