From 35cb9b87b4e083439c936c73ddd3f6c8c1badaa9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mattias=20=C3=84ngehov?= Date: Fri, 23 Dec 2022 22:15:30 +0100 Subject: [PATCH] feat: Allow top-level repo level configs without projects defined (#2853) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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 Signed-off-by: Mattias Ängehov Co-authored-by: PePe Amengual --- server/events/project_command_builder.go | 14 +++++++-- server/events/project_command_builder_test.go | 31 +++++++++++++------ 2 files changed, 33 insertions(+), 12 deletions(-) diff --git a/server/events/project_command_builder.go b/server/events/project_command_builder.go index 731b9c77b7..8ac7de934e 100644 --- a/server/events/project_command_builder.go +++ b/server/events/project_command_builder.go @@ -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, @@ -386,9 +394,9 @@ func (p *DefaultProjectCommandBuilder) buildAllCommandsByCfg(ctx *command.Contex pCfg, commentFlags, repoDir, - DefaultAutomergeEnabled, - DefaultParallelApplyEnabled, - DefaultParallelPlanEnabled, + automerge, + parallelApply, + parallelPlan, verbose, p.TerraformExecutor, )...) diff --git a/server/events/project_command_builder_test.go b/server/events/project_command_builder_test.go index 7122eebb1f..e8f946756a 100644 --- a/server/events/project_command_builder_test.go +++ b/server/events/project_command_builder_test.go @@ -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{} @@ -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, }, }, }, @@ -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) } }) }