diff --git a/server/neptune/workflows/activities/terraform/job.go b/server/neptune/workflows/activities/terraform/job.go index d973a6a6d..64f6cf51f 100644 --- a/server/neptune/workflows/activities/terraform/job.go +++ b/server/neptune/workflows/activities/terraform/job.go @@ -53,4 +53,5 @@ type WorkflowMode int const ( Deploy WorkflowMode = iota PR + Admin ) diff --git a/server/neptune/workflows/internal/terraform/root_fetcher.go b/server/neptune/workflows/internal/terraform/root_fetcher.go index c421d639b..66d6856bc 100644 --- a/server/neptune/workflows/internal/terraform/root_fetcher.go +++ b/server/neptune/workflows/internal/terraform/root_fetcher.go @@ -27,6 +27,10 @@ func (r *RootFetcher) Fetch(ctx workflow.Context) (*terraform.LocalRoot, func(wo return nil, func(_ workflow.Context) error { return nil }, err } + if r.Request.WorkflowMode == terraform.Admin { + return fetchRootResponse.LocalRoot, func(c workflow.Context) error { return nil }, nil + } + return fetchRootResponse.LocalRoot, func(c workflow.Context) error { var cleanupResponse activities.CleanupResponse err = workflow.ExecuteActivity(c, r.Ta.Cleanup, activities.CleanupRequest{ //nolint:gosimple // unnecessary to add a method to convert reponses diff --git a/server/neptune/workflows/internal/terraform/workflow.go b/server/neptune/workflows/internal/terraform/workflow.go index e1b0ad558..98e08aa4c 100644 --- a/server/neptune/workflows/internal/terraform/workflow.go +++ b/server/neptune/workflows/internal/terraform/workflow.go @@ -350,6 +350,10 @@ func (r *Runner) run(ctx workflow.Context) (Response, error) { return Response{}, r.toExternalError(err, "running plan job") } + if r.Request.WorkflowMode == terraform.Admin { + return Response{}, nil + } + if r.Request.WorkflowMode == terraform.PR { validationResults, err := r.Validate(ctx, root, response.ServerURL, planResponse.PlanJSONFile) if err != nil { diff --git a/server/neptune/workflows/internal/terraform/workflow_test.go b/server/neptune/workflows/internal/terraform/workflow_test.go index c08b687f3..bb17b6dc0 100644 --- a/server/neptune/workflows/internal/terraform/workflow_test.go +++ b/server/neptune/workflows/internal/terraform/workflow_test.go @@ -176,6 +176,10 @@ func testTerraformWorkflow(ctx workflow.Context, req request) (*response, error) WorkflowMode: req.WorkflowMode, } + if req.WorkflowMode == terraformModel.Admin { + tAct = nil + } + subject := &terraform.Runner{ ReviewGate: &gate.Review{ Timeout: 30 * time.Second, @@ -615,6 +619,88 @@ func TestSuccess_PRMode(t *testing.T) { }, resp.States) } +func TestSuccess_AdminMode(t *testing.T) { + var suite testsuite.WorkflowTestSuite + env := suite.NewTestWorkflowEnvironment() + ga := &githubActivities{} + ta := &terraformActivities{} + env.RegisterActivity(ga) + env.RegisterActivity(ta) + + outputURL, err := url.Parse("www.test.com/jobs/1235") + assert.NoError(t, err) + + // set activity expectations + env.OnActivity(ga.GithubFetchRoot, mock.MatchedBy(func(ctx context.Context) bool { + info := activity.GetInfo(ctx) + + assert.Equal(t, "taskqueue", info.TaskQueue) + assert.Equal(t, 1*time.Minute, info.HeartbeatTimeout) + + return true + }), activities.FetchRootRequest{ + Repo: testGithubRepo, + Root: testLocalRoot.Root, + DeploymentID: testDeploymentID, + }).Return(activities.FetchRootResponse{ + LocalRoot: testLocalRoot, + DeployDirectory: DeployDir, + }, nil) + + // execute workflow + env.ExecuteWorkflow(testTerraformWorkflow, request{ + WorkflowMode: terraformModel.Admin, + }) + assert.True(t, env.IsWorkflowCompleted()) + + var resp response + err = env.GetWorkflowResult(&resp) + assert.NoError(t, err) + + // assert results are expected + env.AssertExpectations(t) + assert.Equal(t, []state.Workflow{ + { + Plan: &state.Job{ + Status: state.WaitingJobStatus, + Output: &state.JobOutput{ + URL: outputURL, + }, + }, + }, + { + Plan: &state.Job{ + Status: state.InProgressJobStatus, + Output: &state.JobOutput{ + URL: outputURL, + }, + }, + }, + { + Plan: &state.Job{ + Status: state.SuccessJobStatus, + Output: &state.JobOutput{ + URL: outputURL, + PlanSummary: planSummary, + }, + }, + }, + { + Plan: &state.Job{ + Status: state.SuccessJobStatus, + Output: &state.JobOutput{ + URL: outputURL, + PlanSummary: planSummary, + }, + }, + Result: state.WorkflowResult{ + Reason: state.SuccessfulCompletionReason, + Status: state.CompleteWorkflowStatus, + }, + }, + }, resp.States) +} + func TestSuccess_PRMode_FailedPolicy(t *testing.T) { var suite testsuite.WorkflowTestSuite env := suite.NewTestWorkflowEnvironment()