From dbb156453a0f434cc1ee862e07ff79bd3840a70a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mattias=20=C3=84ngehov?= Date: Thu, 22 Dec 2022 16:41:01 +0100 Subject: [PATCH 1/2] 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. --- server/events/project_command_builder.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/server/events/project_command_builder.go b/server/events/project_command_builder.go index 6d58a79b96..acf728055b 100644 --- a/server/events/project_command_builder.go +++ b/server/events/project_command_builder.go @@ -354,6 +354,14 @@ func (p *DefaultProjectCommandBuilder) buildPlanAllCommands(ctx *command.Context 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, @@ -363,9 +371,9 @@ func (p *DefaultProjectCommandBuilder) buildPlanAllCommands(ctx *command.Context pCfg, commentFlags, repoDir, - DefaultAutomergeEnabled, - DefaultParallelApplyEnabled, - DefaultParallelPlanEnabled, + automerge, + parallelApply, + parallelPlan, verbose, )...) } From 645f914f01cb84f88885aa5373ed1b24fa0cd322 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mattias=20=C3=84ngehov?= Date: Thu, 22 Dec 2022 16:41:33 +0100 Subject: [PATCH 2/2] Add tests for setting top-level keys w/o projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Ängehov --- server/events/project_command_builder_test.go | 31 +++++++++++++------ 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/server/events/project_command_builder_test.go b/server/events/project_command_builder_test.go index 9c3f8b8349..38ef70e3a3 100644 --- a/server/events/project_command_builder_test.go +++ b/server/events/project_command_builder_test.go @@ -629,9 +629,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{} @@ -673,19 +676,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, }, }, }, @@ -797,6 +808,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) } }) }