Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Allow top-level repo level configs without projects defined #2853

Merged
merged 3 commits into from
Dec 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
Copy link
Contributor

@krrrr38 krrrr38 Dec 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good. I got that buildAllProjectCommands consider these changes in buildProjectCommandCtx. But plan uses specific buildPlanAllCommands method and it doesn't support this feature. So this PR changes buildPlanAllCommands 👌

BTW, events.DefaultAutomergeEnabled and raw.DefaultAutomerge are duplicated. How about changing them and removing events.DefaultAutomergeEnabled?

			automerge := raw.DefaultAutomerge
			parallelApply := raw.DefaultParallelApply
			parallelPlan := raw.DefaultParallelPlan

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MattiasAng would you consider the above changes before merging?

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