Skip to content

Commit

Permalink
change admin to adhoc, also check why we dont exit early
Browse files Browse the repository at this point in the history
  • Loading branch information
smonero committed Mar 11, 2024
1 parent 2a0da82 commit b3cac15
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 12 deletions.
2 changes: 1 addition & 1 deletion server/neptune/workflows/activities/terraform/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,5 @@ type WorkflowMode int
const (
Deploy WorkflowMode = iota
PR
Admin
Adhoc
)
4 changes: 3 additions & 1 deletion server/neptune/workflows/internal/terraform/job/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package job

import (
"context"

"github.com/runatlantis/atlantis/server/neptune/workflows/activities/command"

key "github.com/runatlantis/atlantis/server/neptune/context"
Expand Down Expand Up @@ -215,7 +216,8 @@ func (r *JobRunner) apply(executionCtx *ExecutionContext, planFile string, step
}

func (r *JobRunner) plan(ctx *ExecutionContext, mode *terraform.PlanMode, workflowMode terraform.WorkflowMode, extraArgs []string) (activities.TerraformPlanResponse, error) {
if workflowMode == terraform.Admin {
// TODO: Don't we already check this earlier? Why are we checking again, is there somewhere else this can get called?
if workflowMode == terraform.Adhoc {
// Admin mode doesn't need to run a plan.
return activities.TerraformPlanResponse{}, nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ 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 {
if r.Request.WorkflowMode == terraform.Adhoc {
return fetchRootResponse.LocalRoot, func(c workflow.Context) error { return nil }, nil
}

Expand Down
13 changes: 8 additions & 5 deletions server/neptune/workflows/internal/terraform/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ package terraform
import (
"context"
"fmt"
"github.com/runatlantis/atlantis/server/neptune/workflows/activities/conftest"
"net/url"
"time"

"github.com/runatlantis/atlantis/server/neptune/workflows/activities/conftest"

key "github.com/runatlantis/atlantis/server/neptune/context"
"go.temporal.io/api/enums/v1"
"go.temporal.io/sdk/client"
Expand Down Expand Up @@ -341,6 +342,12 @@ func (r *Runner) run(ctx workflow.Context) (Response, error) {
if err != nil {
return Response{}, r.toExternalError(err, "fetching root")
}

// if we are in adhoc / terraform admin mode, we don't need to cleanup, plan, validate, or apply
if r.Request.WorkflowMode == terraform.Adhoc {
return Response{}, nil
}

defer func() {
r.executeCleanup(ctx, cleanup)
}()
Expand All @@ -350,10 +357,6 @@ 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 {
Expand Down
9 changes: 5 additions & 4 deletions server/neptune/workflows/internal/terraform/workflow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import (
"context"
"errors"
"fmt"
"github.com/runatlantis/atlantis/server/neptune/workflows/activities/conftest"
"net/url"
"testing"
"time"

"github.com/runatlantis/atlantis/server/neptune/workflows/activities/conftest"

"go.temporal.io/sdk/activity"
"go.temporal.io/sdk/client"

Expand Down Expand Up @@ -176,7 +177,7 @@ func testTerraformWorkflow(ctx workflow.Context, req request) (*response, error)
WorkflowMode: req.WorkflowMode,
}

if req.WorkflowMode == terraformModel.Admin {
if req.WorkflowMode == terraformModel.Adhoc {
tAct = nil
}

Expand Down Expand Up @@ -619,7 +620,7 @@ func TestSuccess_PRMode(t *testing.T) {
}, resp.States)
}

func TestSuccess_AdminMode(t *testing.T) {
func TestSuccess_AdhocMode(t *testing.T) {
var suite testsuite.WorkflowTestSuite
env := suite.NewTestWorkflowEnvironment()
ga := &githubActivities{}
Expand Down Expand Up @@ -649,7 +650,7 @@ func TestSuccess_AdminMode(t *testing.T) {

// execute workflow
env.ExecuteWorkflow(testTerraformWorkflow, request{
WorkflowMode: terraformModel.Admin,
WorkflowMode: terraformModel.Adhoc,
})
assert.True(t, env.IsWorkflowCompleted())

Expand Down

0 comments on commit b3cac15

Please sign in to comment.