Skip to content

Commit

Permalink
feat: Allow top-level repo level configs without projects defined (#2853
Browse files Browse the repository at this point in the history
)

* Allow top repo cfg keys to bet set w/o projects

This will enable top-level keys to be set in `atlantis.yaml` even when
using autoplanning strategy.

* Add tests for setting top-level keys w/o projects

Signed-off-by: Mattias Ängehov <[email protected]>

Signed-off-by: Mattias Ängehov <[email protected]>
Co-authored-by: PePe Amengual <[email protected]>
  • Loading branch information
MattiasAng and jamengual authored Dec 23, 2022
1 parent 9345d55 commit 35cb9b8
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 12 deletions.
14 changes: 11 additions & 3 deletions server/events/project_command_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,14 @@ func (p *DefaultProjectCommandBuilder) buildAllCommandsByCfg(ctx *command.Contex
if err != nil {
return nil, errors.Wrapf(err, "looking for Terraform Cloud workspace from configuration %s", repoDir)
}
automerge := DefaultAutomergeEnabled
parallelApply := DefaultParallelApplyEnabled
parallelPlan := DefaultParallelPlanEnabled
if hasRepoCfg {
automerge = repoCfg.Automerge
parallelApply = repoCfg.ParallelApply
parallelPlan = repoCfg.ParallelPlan
}
pCfg := p.GlobalCfg.DefaultProjCfg(ctx.Log, ctx.Pull.BaseRepo.ID(), mp.Path, pWorkspace)

projCtxs = append(projCtxs,
Expand All @@ -386,9 +394,9 @@ func (p *DefaultProjectCommandBuilder) buildAllCommandsByCfg(ctx *command.Contex
pCfg,
commentFlags,
repoDir,
DefaultAutomergeEnabled,
DefaultParallelApplyEnabled,
DefaultParallelPlanEnabled,
automerge,
parallelApply,
parallelPlan,
verbose,
p.TerraformExecutor,
)...)
Expand Down
31 changes: 22 additions & 9 deletions server/events/project_command_builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -642,9 +642,12 @@ func TestDefaultProjectCommandBuilder_BuildPlanCommands(t *testing.T) {
// Since we're focused on autoplanning here, we don't validate all the
// fields so the tests are more obvious and targeted.
type expCtxFields struct {
ProjectName string
RepoRelDir string
Workspace string
ProjectName string
RepoRelDir string
Workspace string
Automerge bool
ParallelPlanEnabled bool
ParallelApplyEnabled bool
}
cases := map[string]struct {
DirStructure map[string]interface{}
Expand Down Expand Up @@ -686,19 +689,27 @@ func TestDefaultProjectCommandBuilder_BuildPlanCommands(t *testing.T) {
},
AtlantisYAML: `
version: 3
automerge: true
parallel_plan: true
parallel_apply: true
`,
ModifiedFiles: []string{"project1/main.tf", "project2/main.tf"},
Exp: []expCtxFields{
{
ProjectName: "",
RepoRelDir: "project1",
Workspace: "default",
ProjectName: "",
RepoRelDir: "project1",
Workspace: "default",
Automerge: true,
ParallelApplyEnabled: true,
ParallelPlanEnabled: true,
},
{
ProjectName: "",
RepoRelDir: "project2",
Workspace: "default",
ProjectName: "",
RepoRelDir: "project2",
Workspace: "default",
Automerge: true,
ParallelApplyEnabled: true,
ParallelPlanEnabled: true,
},
},
},
Expand Down Expand Up @@ -814,6 +825,8 @@ projects:
Equals(t, expCtx.ProjectName, actCtx.ProjectName)
Equals(t, expCtx.RepoRelDir, actCtx.RepoRelDir)
Equals(t, expCtx.Workspace, actCtx.Workspace)
Equals(t, expCtx.ParallelPlanEnabled, actCtx.ParallelPlanEnabled)
Equals(t, expCtx.ParallelApplyEnabled, actCtx.ParallelApplyEnabled)
}
})
}
Expand Down

0 comments on commit 35cb9b8

Please sign in to comment.