From 1b9ca74f82c14ff9c63c5935730a6405dafd2af7 Mon Sep 17 00:00:00 2001 From: Marcelo Medeiros Date: Fri, 13 Oct 2023 13:04:56 +0200 Subject: [PATCH] add flag to allow the user disable the autodiscover --- .../events/events_controller_e2e_test.go | 1 + server/core/config/parser_validator_test.go | 63 ++++- server/core/config/raw/autodiscover.go | 32 +++ server/core/config/raw/autodiscover_test.go | 115 +++++++++ server/core/config/raw/repo_cfg.go | 11 + server/core/config/raw/repo_cfg_test.go | 46 +++- server/core/config/valid/repo_cfg.go | 6 + server/core/config/valid/valid.go | 1 + server/events/command/project_context.go | 3 + server/events/project_command_builder.go | 45 +++- .../project_command_builder_internal_test.go | 219 ++++++++++-------- server/events/project_command_builder_test.go | 72 +++++- .../events/project_command_context_builder.go | 18 +- .../project_command_context_builder_test.go | 8 +- server/server.go | 1 + server/user_config.go | 68 +++--- 16 files changed, 542 insertions(+), 167 deletions(-) create mode 100644 server/core/config/raw/autodiscover.go create mode 100644 server/core/config/raw/autodiscover_test.go diff --git a/server/controllers/events/events_controller_e2e_test.go b/server/controllers/events/events_controller_e2e_test.go index 93c63df3bd..d585a6ac71 100644 --- a/server/controllers/events/events_controller_e2e_test.go +++ b/server/controllers/events/events_controller_e2e_test.go @@ -1319,6 +1319,7 @@ func setupE2E(t *testing.T, repoDir string, opt setupOption) (events_controllers false, false, false, + valid.Autodiscover{Enabled: true}, false, false, "", diff --git a/server/core/config/parser_validator_test.go b/server/core/config/parser_validator_test.go index 53caf9e539..afb5b83831 100644 --- a/server/core/config/parser_validator_test.go +++ b/server/core/config/parser_validator_test.go @@ -180,6 +180,7 @@ workflows: StateRm: valid.DefaultStateRmStage, }, }, + Autodiscover: &valid.Autodiscover{Enabled: true}, }, }, @@ -190,9 +191,10 @@ workflows: version: 3 projects:`, exp: valid.RepoCfg{ - Version: 3, - Projects: nil, - Workflows: map[string]valid.Workflow{}, + Version: 3, + Projects: nil, + Workflows: map[string]valid.Workflow{}, + Autodiscover: &valid.Autodiscover{Enabled: true}, }, }, { @@ -224,7 +226,8 @@ projects: ApplyRequirements: nil, }, }, - Workflows: map[string]valid.Workflow{}, + Workflows: map[string]valid.Workflow{}, + Autodiscover: &valid.Autodiscover{Enabled: true}, }, }, { @@ -246,7 +249,8 @@ projects: }, }, }, - Workflows: make(map[string]valid.Workflow), + Workflows: make(map[string]valid.Workflow), + Autodiscover: &valid.Autodiscover{Enabled: true}, }, }, { @@ -270,7 +274,32 @@ projects: }, }, }, - Workflows: make(map[string]valid.Workflow), + Workflows: make(map[string]valid.Workflow), + Autodiscover: &valid.Autodiscover{Enabled: true}, + }, + }, + { + description: "autodiscover should be enabled by default", + input: ` +version: 3 +`, + exp: valid.RepoCfg{ + Version: 3, + Autodiscover: &valid.Autodiscover{Enabled: true}, + Workflows: make(map[string]valid.Workflow), + }, + }, + { + description: "disable autodiscover", + input: ` +version: 3 +autodiscover: + enabled: false +`, + exp: valid.RepoCfg{ + Version: 3, + Autodiscover: &valid.Autodiscover{Enabled: false}, + Workflows: make(map[string]valid.Workflow), }, }, { @@ -292,7 +321,8 @@ projects: }, }, }, - Workflows: make(map[string]valid.Workflow), + Workflows: make(map[string]valid.Workflow), + Autodiscover: &valid.Autodiscover{Enabled: true}, }, }, { @@ -315,7 +345,8 @@ workflows: ~ }, }, }, - Workflows: make(map[string]valid.Workflow), + Workflows: make(map[string]valid.Workflow), + Autodiscover: &valid.Autodiscover{Enabled: true}, }, }, { @@ -346,6 +377,7 @@ workflows: Workflows: map[string]valid.Workflow{ "default": defaultWorkflow("default"), }, + Autodiscover: &valid.Autodiscover{Enabled: true}, }, }, { @@ -378,6 +410,7 @@ workflows: Workflows: map[string]valid.Workflow{ "myworkflow": defaultWorkflow("myworkflow"), }, + Autodiscover: &valid.Autodiscover{Enabled: true}, }, }, { @@ -412,6 +445,7 @@ workflows: Workflows: map[string]valid.Workflow{ "myworkflow": defaultWorkflow("myworkflow"), }, + Autodiscover: &valid.Autodiscover{Enabled: true}, }, }, { @@ -446,6 +480,7 @@ workflows: Workflows: map[string]valid.Workflow{ "myworkflow": defaultWorkflow("myworkflow"), }, + Autodiscover: &valid.Autodiscover{Enabled: true}, }, }, { @@ -480,6 +515,7 @@ workflows: Workflows: map[string]valid.Workflow{ "myworkflow": defaultWorkflow("myworkflow"), }, + Autodiscover: &valid.Autodiscover{Enabled: true}, }, }, { @@ -514,6 +550,7 @@ workflows: Workflows: map[string]valid.Workflow{ "myworkflow": defaultWorkflow("myworkflow"), }, + Autodiscover: &valid.Autodiscover{Enabled: true}, }, }, { @@ -548,6 +585,7 @@ workflows: Workflows: map[string]valid.Workflow{ "myworkflow": defaultWorkflow("myworkflow"), }, + Autodiscover: &valid.Autodiscover{Enabled: true}, }, }, { @@ -582,6 +620,7 @@ workflows: Workflows: map[string]valid.Workflow{ "myworkflow": defaultWorkflow("myworkflow"), }, + Autodiscover: &valid.Autodiscover{Enabled: true}, }, }, { @@ -616,6 +655,7 @@ workflows: Workflows: map[string]valid.Workflow{ "myworkflow": defaultWorkflow("myworkflow"), }, + Autodiscover: &valid.Autodiscover{Enabled: true}, }, }, { @@ -731,7 +771,8 @@ projects: }, }, }, - Workflows: map[string]valid.Workflow{}, + Workflows: map[string]valid.Workflow{}, + Autodiscover: &valid.Autodiscover{Enabled: true}, }, }, { @@ -822,6 +863,7 @@ workflows: }, }, }, + Autodiscover: &valid.Autodiscover{Enabled: true}, }, }, { @@ -925,6 +967,7 @@ workflows: }, }, }, + Autodiscover: &valid.Autodiscover{Enabled: true}, }, }, { @@ -1008,6 +1051,7 @@ workflows: }, }, }, + Autodiscover: &valid.Autodiscover{Enabled: true}, }, }, { @@ -1106,6 +1150,7 @@ workflows: }, }, }, + Autodiscover: &valid.Autodiscover{Enabled: true}, }, }, } diff --git a/server/core/config/raw/autodiscover.go b/server/core/config/raw/autodiscover.go new file mode 100644 index 0000000000..03f08ba15d --- /dev/null +++ b/server/core/config/raw/autodiscover.go @@ -0,0 +1,32 @@ +package raw + +import ( + "github.com/runatlantis/atlantis/server/core/config/valid" +) + +type Autodiscover struct { + Enabled *bool `yaml:"enabled,omitempty"` +} + +func (a Autodiscover) ToValid() valid.Autodiscover { + var v valid.Autodiscover + + if a.Enabled == nil { + v.Enabled = true + } else { + v.Enabled = *a.Enabled + } + + return v +} + +func (a Autodiscover) Validate() error { + return nil +} + +// DefaultAutoDiscover returns the default autodiscover config. +func DefaultAutoDiscover() valid.Autodiscover { + return valid.Autodiscover{ + Enabled: valid.DefaultAutoDiscoverEnabled, + } +} diff --git a/server/core/config/raw/autodiscover_test.go b/server/core/config/raw/autodiscover_test.go new file mode 100644 index 0000000000..1805065798 --- /dev/null +++ b/server/core/config/raw/autodiscover_test.go @@ -0,0 +1,115 @@ +package raw_test + +import ( + "testing" + + "github.com/runatlantis/atlantis/server/core/config/raw" + "github.com/runatlantis/atlantis/server/core/config/valid" + . "github.com/runatlantis/atlantis/testing" + yaml "gopkg.in/yaml.v2" +) + +func TestAutoDiscover_UnmarshalYAML(t *testing.T) { + cases := []struct { + description string + input string + exp raw.Autodiscover + }{ + { + description: "omit unset fields", + input: "", + exp: raw.Autodiscover{ + Enabled: nil, + }, + }, + { + description: "enabled true", + input: ` +enabled: true +`, + exp: raw.Autodiscover{ + Enabled: Bool(true), + }, + }, + { + description: "enabled false", + input: ` +enabled: false +`, + exp: raw.Autodiscover{ + Enabled: Bool(false), + }, + }, + } + + for _, c := range cases { + t.Run(c.description, func(t *testing.T) { + var a raw.Autodiscover + err := yaml.UnmarshalStrict([]byte(c.input), &a) + Ok(t, err) + Equals(t, c.exp, a) + }) + } +} + +func TestAutodiscover_Validate(t *testing.T) { + cases := []struct { + description string + input raw.Autodiscover + }{ + { + description: "nothing set", + input: raw.Autodiscover{}, + }, + { + description: "enabled false", + input: raw.Autodiscover{ + Enabled: Bool(false), + }, + }, + } + for _, c := range cases { + t.Run(c.description, func(t *testing.T) { + Ok(t, c.input.Validate()) + }) + } +} + +func TestAutodiscover_ToValid(t *testing.T) { + cases := []struct { + description string + input raw.Autodiscover + exp valid.Autodiscover + }{ + { + description: "nothing set", + input: raw.Autodiscover{}, + exp: valid.Autodiscover{ + Enabled: true, + }, + }, + { + description: "enabled false", + input: raw.Autodiscover{ + Enabled: Bool(false), + }, + exp: valid.Autodiscover{ + Enabled: false, + }, + }, + { + description: "enabled true", + input: raw.Autodiscover{ + Enabled: Bool(true), + }, + exp: valid.Autodiscover{ + Enabled: true, + }, + }, + } + for _, c := range cases { + t.Run(c.description, func(t *testing.T) { + Equals(t, c.exp, c.input.ToValid()) + }) + } +} diff --git a/server/core/config/raw/repo_cfg.go b/server/core/config/raw/repo_cfg.go index eb511b04aa..021575c43f 100644 --- a/server/core/config/raw/repo_cfg.go +++ b/server/core/config/raw/repo_cfg.go @@ -20,6 +20,7 @@ type RepoCfg struct { Workflows map[string]Workflow `yaml:"workflows,omitempty"` PolicySets PolicySets `yaml:"policies,omitempty"` Automerge *bool `yaml:"automerge,omitempty"` + Autodiscover *Autodiscover `yaml:"autodiscover,omitempty"` ParallelApply *bool `yaml:"parallel_apply,omitempty"` ParallelPlan *bool `yaml:"parallel_plan,omitempty"` DeleteSourceBranchOnMerge *bool `yaml:"delete_source_branch_on_merge,omitempty"` @@ -57,6 +58,15 @@ func (r RepoCfg) ToValid() valid.RepoCfg { validProjects = append(validProjects, p.ToValid()) } + var autodiscover *valid.Autodiscover + if r.Autodiscover == nil { + defaultAutoDiscover := DefaultAutoDiscover() + autodiscover = &defaultAutoDiscover + } else { + validAutoDiscover := r.Autodiscover.ToValid() + autodiscover = &validAutoDiscover + } + automerge := r.Automerge parallelApply := r.ParallelApply parallelPlan := r.ParallelPlan @@ -76,6 +86,7 @@ func (r RepoCfg) ToValid() valid.RepoCfg { Projects: validProjects, Workflows: validWorkflows, Automerge: automerge, + Autodiscover: autodiscover, ParallelApply: parallelApply, ParallelPlan: parallelPlan, ParallelPolicyCheck: parallelPlan, diff --git a/server/core/config/raw/repo_cfg_test.go b/server/core/config/raw/repo_cfg_test.go index 7b11655c13..783fe155b0 100644 --- a/server/core/config/raw/repo_cfg_test.go +++ b/server/core/config/raw/repo_cfg_test.go @@ -126,6 +126,8 @@ func TestConfig_UnmarshalYAML(t *testing.T) { input: ` version: 3 automerge: true +autodiscover: + enabled: true parallel_apply: true parallel_plan: false projects: @@ -149,8 +151,11 @@ allowed_regexp_prefixes: - dev/ - staging/`, exp: raw.RepoCfg{ - Version: Int(3), - Automerge: Bool(true), + Version: Int(3), + Automerge: Bool(true), + Autodiscover: &raw.Autodiscover{ + Enabled: Bool(true), + }, ParallelApply: Bool(true), ParallelPlan: Bool(false), Projects: []raw.Project{ @@ -241,21 +246,24 @@ func TestConfig_ToValid(t *testing.T) { description: "nothing set", input: raw.RepoCfg{Version: Int(2)}, exp: valid.RepoCfg{ - Version: 2, - Workflows: make(map[string]valid.Workflow), + Version: 2, + Workflows: make(map[string]valid.Workflow), + Autodiscover: &valid.Autodiscover{Enabled: true}, }, }, { description: "set to empty", input: raw.RepoCfg{ - Version: Int(2), - Workflows: map[string]raw.Workflow{}, - Projects: []raw.Project{}, + Version: Int(2), + Workflows: map[string]raw.Workflow{}, + Projects: []raw.Project{}, + Autodiscover: &raw.Autodiscover{Enabled: Bool(true)}, }, exp: valid.RepoCfg{ - Version: 2, - Workflows: map[string]valid.Workflow{}, - Projects: nil, + Version: 2, + Workflows: map[string]valid.Workflow{}, + Projects: nil, + Autodiscover: &valid.Autodiscover{Enabled: true}, }, }, { @@ -269,6 +277,7 @@ func TestConfig_ToValid(t *testing.T) { ParallelApply: nil, AbortOnExcecutionOrderFail: false, Workflows: map[string]valid.Workflow{}, + Autodiscover: &valid.Autodiscover{Enabled: true}, }, }, { @@ -285,6 +294,7 @@ func TestConfig_ToValid(t *testing.T) { ParallelApply: Bool(true), AbortOnExcecutionOrderFail: true, Workflows: map[string]valid.Workflow{}, + Autodiscover: &valid.Autodiscover{Enabled: true}, }, }, { @@ -301,6 +311,19 @@ func TestConfig_ToValid(t *testing.T) { ParallelApply: Bool(false), AbortOnExcecutionOrderFail: false, Workflows: map[string]valid.Workflow{}, + Autodiscover: &valid.Autodiscover{Enabled: true}, + }, + }, + { + description: "autodiscover false", + input: raw.RepoCfg{ + Version: Int(2), + Autodiscover: &raw.Autodiscover{Enabled: Bool(false)}, + }, + exp: valid.RepoCfg{ + Version: 2, + Autodiscover: &valid.Autodiscover{Enabled: false}, + Workflows: map[string]valid.Workflow{}, }, }, { @@ -331,6 +354,7 @@ func TestConfig_ToValid(t *testing.T) { StateRm: valid.DefaultStateRmStage, }, }, + Autodiscover: &valid.Autodiscover{Enabled: true}, }, }, { @@ -338,6 +362,7 @@ func TestConfig_ToValid(t *testing.T) { input: raw.RepoCfg{ Version: Int(2), Automerge: Bool(true), + Autodiscover: &raw.Autodiscover{Enabled: Bool(true)}, ParallelApply: Bool(true), Workflows: map[string]raw.Workflow{ "myworkflow": { @@ -387,6 +412,7 @@ func TestConfig_ToValid(t *testing.T) { exp: valid.RepoCfg{ Version: 2, Automerge: Bool(true), + Autodiscover: &valid.Autodiscover{Enabled: true}, ParallelApply: Bool(true), Workflows: map[string]valid.Workflow{ "myworkflow": { diff --git a/server/core/config/valid/repo_cfg.go b/server/core/config/valid/repo_cfg.go index fe441f4d05..e2fdf5c04c 100644 --- a/server/core/config/valid/repo_cfg.go +++ b/server/core/config/valid/repo_cfg.go @@ -19,6 +19,7 @@ type RepoCfg struct { Workflows map[string]Workflow PolicySets PolicySets Automerge *bool + Autodiscover *Autodiscover ParallelApply *bool ParallelPlan *bool ParallelPolicyCheck *bool @@ -129,6 +130,7 @@ type Project struct { WorkflowName *string TerraformVersion *version.Version Autoplan Autoplan + Autodiscover Autodiscover PlanRequirements []string ApplyRequirements []string ImportRequirements []string @@ -148,6 +150,10 @@ func (p Project) GetName() string { return "" } +type Autodiscover struct { + Enabled bool +} + type Autoplan struct { WhenModified []string Enabled bool diff --git a/server/core/config/valid/valid.go b/server/core/config/valid/valid.go index 7fa35827a0..c638451f19 100644 --- a/server/core/config/valid/valid.go +++ b/server/core/config/valid/valid.go @@ -3,3 +3,4 @@ package valid const DefaultAutoPlanEnabled = true +const DefaultAutoDiscoverEnabled = true diff --git a/server/events/command/project_context.go b/server/events/command/project_context.go index 1e2521e38c..c75fa19d3e 100644 --- a/server/events/command/project_context.go +++ b/server/events/command/project_context.go @@ -38,6 +38,9 @@ type ProjectContext struct { // AutomergeEnabled is true if automerge is enabled for the repo that this // project is in. AutomergeEnabled bool + //AutodiscoverEnabled is true if autodiscover is enabled for the repo that this + // project is in. + AutodiscoverEnabled valid.Autodiscover // ParallelApplyEnabled is true if parallel apply is enabled for this project. ParallelApplyEnabled bool // ParallelPlanEnabled is true if parallel plan is enabled for this project. diff --git a/server/events/project_command_builder.go b/server/events/project_command_builder.go index 2347c9072a..34d88ec528 100644 --- a/server/events/project_command_builder.go +++ b/server/events/project_command_builder.go @@ -28,6 +28,14 @@ const ( // DefaultWorkspace is the default Terraform workspace we run commands in. // This is also Terraform's default workspace. DefaultWorkspace = "default" + // DefaultAutomergeEnabled is the default for the automerge setting. + DefaultAutomergeEnabled = false + // DefaultAutoDiscoverEnabled is the default for the auto discover setting. + DefaultAutoDiscoverEnabled = true + // DefaultParallelApplyEnabled is the default for the parallel apply setting. + DefaultParallelApplyEnabled = false + // DefaultParallelPlanEnabled is the default for the parallel plan setting. + DefaultParallelPlanEnabled = false // DefaultDeleteSourceBranchOnMerge being false is the default setting whether or not to remove a source branch on merge DefaultDeleteSourceBranchOnMerge = false // DefaultAbortOnExcecutionOrderFail being false is the default setting for abort on execution group failiures @@ -47,6 +55,7 @@ func NewInstrumentedProjectCommandBuilder( skipCloneNoChanges bool, EnableRegExpCmd bool, EnableAutoMerge bool, + EnableAutoDiscover valid.Autodiscover, EnableParallelPlan bool, EnableParallelApply bool, AutoDetectModuleFiles string, @@ -78,6 +87,7 @@ func NewInstrumentedProjectCommandBuilder( skipCloneNoChanges, EnableRegExpCmd, EnableAutoMerge, + EnableAutoDiscover, EnableParallelPlan, EnableParallelApply, AutoDetectModuleFiles, @@ -107,6 +117,7 @@ func NewProjectCommandBuilder( skipCloneNoChanges bool, EnableRegExpCmd bool, EnableAutoMerge bool, + EnableAutoDiscover valid.Autodiscover, EnableParallelPlan bool, EnableParallelApply bool, AutoDetectModuleFiles string, @@ -129,6 +140,7 @@ func NewProjectCommandBuilder( SkipCloneNoChanges: skipCloneNoChanges, EnableRegExpCmd: EnableRegExpCmd, EnableAutoMerge: EnableAutoMerge, + EnableAutoDiscover: EnableAutoDiscover, EnableParallelPlan: EnableParallelPlan, EnableParallelApply: EnableParallelApply, AutoDetectModuleFiles: AutoDetectModuleFiles, @@ -226,6 +238,8 @@ type DefaultProjectCommandBuilder struct { EnableRegExpCmd bool // User config option: Automatically merge pull requests after all plans have been successfully applied. EnableAutoMerge bool + // User config option: Enables auto-discovery of projects in a repository. + EnableAutoDiscover valid.Autodiscover // User config option: Whether to run plan operations in parallel. EnableParallelPlan bool // User config option: Whether to run apply operations in parallel. @@ -360,7 +374,11 @@ func (p *DefaultProjectCommandBuilder) buildAllCommandsByCfg(ctx *command.Contex return []command.ProjectContext{}, nil } } else { - ctx.Log.Info("No projects are defined in %s. Will resume automatic detection", repoCfgFile) + if !repoCfg.Autodiscover.Enabled { + ctx.Log.Info("No projects are defined in %s. Auto discovery is disabled. Will skip automatic detection", repoCfgFile) + return []command.ProjectContext{}, nil + } + ctx.Log.Info("No projects are defined in %s. Auto discovery is enabled, will resume automatic detection", repoCfgFile) } // NOTE: We discard this work here and end up doing it again after // cloning to ensure all the return values are set properly with @@ -411,6 +429,7 @@ func (p *DefaultProjectCommandBuilder) buildAllCommandsByCfg(ctx *command.Contex ctx.Log.Debug("moduleInfo for %s (matching %q) = %v", repoDir, p.AutoDetectModuleFiles, moduleInfo) automerge := p.EnableAutoMerge + autodiscover := p.EnableAutoDiscover parallelApply := p.EnableParallelApply parallelPlan := p.EnableParallelPlan abortOnExcecutionOrderFail := DefaultAbortOnExcecutionOrderFail @@ -418,6 +437,11 @@ func (p *DefaultProjectCommandBuilder) buildAllCommandsByCfg(ctx *command.Contex if repoCfg.Automerge != nil { automerge = *repoCfg.Automerge } + if repoCfg.Autodiscover != nil { + autodiscover = *repoCfg.Autodiscover + } else { + autodiscover = valid.Autodiscover{Enabled: DefaultAutoDiscoverEnabled} + } if repoCfg.ParallelApply != nil { parallelApply = *repoCfg.ParallelApply } @@ -447,10 +471,11 @@ func (p *DefaultProjectCommandBuilder) buildAllCommandsByCfg(ctx *command.Contex commentFlags, repoDir, automerge, + autodiscover, parallelApply, parallelPlan, verbose, - repoCfg.AbortOnExcecutionOrderFail, + abortOnExcecutionOrderFail, p.TerraformExecutor, )...) } @@ -458,7 +483,11 @@ func (p *DefaultProjectCommandBuilder) buildAllCommandsByCfg(ctx *command.Contex // If there is no config file or it specified no projects, then we'll plan each project that // our algorithm determines was modified. if hasRepoCfg { - ctx.Log.Info("No projects are defined in %s. Will resume automatic detection", repoCfgFile) + if !repoCfg.Autodiscover.Enabled { + ctx.Log.Info("No projects are defined in %s. Auto discovery is disabled. Will skip automatic detection", repoCfgFile) + return []command.ProjectContext{}, nil + } + ctx.Log.Info("No projects are defined in %s. Auto discovery is enabled, will resume automatic detection", repoCfgFile) } else { ctx.Log.Info("found no %s file", repoCfgFile) } @@ -483,6 +512,7 @@ func (p *DefaultProjectCommandBuilder) buildAllCommandsByCfg(ctx *command.Contex commentFlags, repoDir, automerge, + autodiscover, parallelApply, parallelPlan, verbose, @@ -772,7 +802,9 @@ func (p *DefaultProjectCommandBuilder) buildProjectCommandCtx(ctx *command.Conte } var projCtxs []command.ProjectContext var projCfg valid.MergedProjectCfg + automerge := p.EnableAutoMerge + autodiscover := p.EnableAutoDiscover parallelApply := p.EnableParallelApply parallelPlan := p.EnableParallelPlan abortOnExcecutionOrderFail := DefaultAbortOnExcecutionOrderFail @@ -780,6 +812,11 @@ func (p *DefaultProjectCommandBuilder) buildProjectCommandCtx(ctx *command.Conte if repoCfgPtr.Automerge != nil { automerge = *repoCfgPtr.Automerge } + if repoCfgPtr.Autodiscover != nil { + autodiscover = *repoCfgPtr.Autodiscover + } else { + autodiscover = valid.Autodiscover{Enabled: true} + } if repoCfgPtr.ParallelApply != nil { parallelApply = *repoCfgPtr.ParallelApply } @@ -808,6 +845,7 @@ func (p *DefaultProjectCommandBuilder) buildProjectCommandCtx(ctx *command.Conte commentFlags, repoDir, automerge, + autodiscover, parallelApply, parallelPlan, verbose, @@ -832,6 +870,7 @@ func (p *DefaultProjectCommandBuilder) buildProjectCommandCtx(ctx *command.Conte commentFlags, repoDir, automerge, + autodiscover, parallelApply, parallelPlan, verbose, diff --git a/server/events/project_command_builder_internal_test.go b/server/events/project_command_builder_internal_test.go index e8804c5142..18ee0f9890 100644 --- a/server/events/project_command_builder_internal_test.go +++ b/server/events/project_command_builder_internal_test.go @@ -61,15 +61,16 @@ workflows: - apply`, repoCfg: "", expCtx: command.ProjectContext{ - ApplyCmd: "atlantis apply -d project1 -w myworkspace", - ApprovePoliciesCmd: "atlantis approve_policies -d project1 -w myworkspace", - BaseRepo: baseRepo, - EscapedCommentArgs: []string{`\f\l\a\g`}, - AutomergeEnabled: false, - AutoplanEnabled: true, - HeadRepo: models.Repo{}, - Log: logger, - Scope: statsScope, + ApplyCmd: "atlantis apply -d project1 -w myworkspace", + ApprovePoliciesCmd: "atlantis approve_policies -d project1 -w myworkspace", + BaseRepo: baseRepo, + EscapedCommentArgs: []string{`\f\l\a\g`}, + AutomergeEnabled: false, + AutodiscoverEnabled: valid.Autodiscover{Enabled: true}, + AutoplanEnabled: true, + HeadRepo: models.Repo{}, + Log: logger, + Scope: statsScope, PullReqStatus: models.PullReqStatus{ Mergeable: true, }, @@ -118,15 +119,16 @@ projects: terraform_version: v10.0 `, expCtx: command.ProjectContext{ - ApplyCmd: "atlantis apply -d project1 -w myworkspace", - ApprovePoliciesCmd: "atlantis approve_policies -d project1 -w myworkspace", - BaseRepo: baseRepo, - EscapedCommentArgs: []string{`\f\l\a\g`}, - AutomergeEnabled: true, - AutoplanEnabled: true, - HeadRepo: models.Repo{}, - Log: logger, - Scope: statsScope, + ApplyCmd: "atlantis apply -d project1 -w myworkspace", + ApprovePoliciesCmd: "atlantis approve_policies -d project1 -w myworkspace", + BaseRepo: baseRepo, + EscapedCommentArgs: []string{`\f\l\a\g`}, + AutomergeEnabled: true, + AutodiscoverEnabled: valid.Autodiscover{Enabled: true}, + AutoplanEnabled: true, + HeadRepo: models.Repo{}, + Log: logger, + Scope: statsScope, PullReqStatus: models.PullReqStatus{ Mergeable: true, }, @@ -179,15 +181,16 @@ projects: terraform_version: v10.0 `, expCtx: command.ProjectContext{ - ApplyCmd: "atlantis apply -d project1 -w myworkspace", - ApprovePoliciesCmd: "atlantis approve_policies -d project1 -w myworkspace", - BaseRepo: baseRepo, - EscapedCommentArgs: []string{`\f\l\a\g`}, - AutomergeEnabled: true, - AutoplanEnabled: true, - HeadRepo: models.Repo{}, - Log: logger, - Scope: statsScope, + ApplyCmd: "atlantis apply -d project1 -w myworkspace", + ApprovePoliciesCmd: "atlantis approve_policies -d project1 -w myworkspace", + BaseRepo: baseRepo, + EscapedCommentArgs: []string{`\f\l\a\g`}, + AutomergeEnabled: true, + AutodiscoverEnabled: valid.Autodiscover{Enabled: true}, + AutoplanEnabled: true, + HeadRepo: models.Repo{}, + Log: logger, + Scope: statsScope, PullReqStatus: models.PullReqStatus{ Mergeable: true, }, @@ -248,15 +251,16 @@ projects: terraform_version: v10.0 `, expCtx: command.ProjectContext{ - ApplyCmd: "atlantis apply -d project1 -w myworkspace", - ApprovePoliciesCmd: "atlantis approve_policies -d project1 -w myworkspace", - BaseRepo: baseRepo, - EscapedCommentArgs: []string{`\f\l\a\g`}, - AutomergeEnabled: true, - AutoplanEnabled: true, - HeadRepo: models.Repo{}, - Log: logger, - Scope: statsScope, + ApplyCmd: "atlantis apply -d project1 -w myworkspace", + ApprovePoliciesCmd: "atlantis approve_policies -d project1 -w myworkspace", + BaseRepo: baseRepo, + EscapedCommentArgs: []string{`\f\l\a\g`}, + AutomergeEnabled: true, + AutodiscoverEnabled: valid.Autodiscover{Enabled: true}, + AutoplanEnabled: true, + HeadRepo: models.Repo{}, + Log: logger, + Scope: statsScope, PullReqStatus: models.PullReqStatus{ Mergeable: true, }, @@ -384,6 +388,8 @@ workflows: repoCfg: ` version: 3 automerge: true +autodiscover: + enabled: true projects: - dir: project1 workspace: myworkspace @@ -404,15 +410,16 @@ workflows: - apply `, expCtx: command.ProjectContext{ - ApplyCmd: "atlantis apply -d project1 -w myworkspace", - ApprovePoliciesCmd: "atlantis approve_policies -d project1 -w myworkspace", - BaseRepo: baseRepo, - EscapedCommentArgs: []string{`\f\l\a\g`}, - AutomergeEnabled: true, - AutoplanEnabled: true, - HeadRepo: models.Repo{}, - Log: logger, - Scope: statsScope, + ApplyCmd: "atlantis apply -d project1 -w myworkspace", + ApprovePoliciesCmd: "atlantis approve_policies -d project1 -w myworkspace", + BaseRepo: baseRepo, + EscapedCommentArgs: []string{`\f\l\a\g`}, + AutomergeEnabled: true, + AutodiscoverEnabled: valid.Autodiscover{Enabled: true}, + AutoplanEnabled: true, + HeadRepo: models.Repo{}, + Log: logger, + Scope: statsScope, PullReqStatus: models.PullReqStatus{ Mergeable: true, }, @@ -467,15 +474,16 @@ projects: workflow: custom `, expCtx: command.ProjectContext{ - ApplyCmd: "atlantis apply -d project1 -w myworkspace", - ApprovePoliciesCmd: "atlantis approve_policies -d project1 -w myworkspace", - BaseRepo: baseRepo, - EscapedCommentArgs: []string{`\f\l\a\g`}, - AutomergeEnabled: true, - AutoplanEnabled: true, - HeadRepo: models.Repo{}, - Log: logger, - Scope: statsScope, + ApplyCmd: "atlantis apply -d project1 -w myworkspace", + ApprovePoliciesCmd: "atlantis approve_policies -d project1 -w myworkspace", + BaseRepo: baseRepo, + EscapedCommentArgs: []string{`\f\l\a\g`}, + AutomergeEnabled: true, + AutodiscoverEnabled: valid.Autodiscover{Enabled: true}, + AutoplanEnabled: true, + HeadRepo: models.Repo{}, + Log: logger, + Scope: statsScope, PullReqStatus: models.PullReqStatus{ Mergeable: true, }, @@ -517,6 +525,8 @@ workflows: repoCfg: ` version: 3 automerge: true +autodiscover: + enabled: true projects: - dir: project1 workspace: myworkspace @@ -533,15 +543,16 @@ workflows: steps: [] `, expCtx: command.ProjectContext{ - ApplyCmd: "atlantis apply -d project1 -w myworkspace", - ApprovePoliciesCmd: "atlantis approve_policies -d project1 -w myworkspace", - BaseRepo: baseRepo, - EscapedCommentArgs: []string{`\f\l\a\g`}, - AutomergeEnabled: true, - AutoplanEnabled: true, - HeadRepo: models.Repo{}, - Log: logger, - Scope: statsScope, + ApplyCmd: "atlantis apply -d project1 -w myworkspace", + ApprovePoliciesCmd: "atlantis approve_policies -d project1 -w myworkspace", + BaseRepo: baseRepo, + EscapedCommentArgs: []string{`\f\l\a\g`}, + AutomergeEnabled: true, + AutodiscoverEnabled: valid.Autodiscover{Enabled: true}, + AutoplanEnabled: true, + HeadRepo: models.Repo{}, + Log: logger, + Scope: statsScope, PullReqStatus: models.PullReqStatus{ Mergeable: true, }, @@ -585,15 +596,16 @@ projects: workspace: myworkspace `, expCtx: command.ProjectContext{ - ApplyCmd: "atlantis apply -d project1 -w myworkspace", - ApprovePoliciesCmd: "atlantis approve_policies -d project1 -w myworkspace", - BaseRepo: baseRepo, - EscapedCommentArgs: []string{`\f\l\a\g`}, - AutomergeEnabled: false, - AutoplanEnabled: true, - HeadRepo: models.Repo{}, - Log: logger, - Scope: statsScope, + ApplyCmd: "atlantis apply -d project1 -w myworkspace", + ApprovePoliciesCmd: "atlantis approve_policies -d project1 -w myworkspace", + BaseRepo: baseRepo, + EscapedCommentArgs: []string{`\f\l\a\g`}, + AutomergeEnabled: false, + AutodiscoverEnabled: valid.Autodiscover{Enabled: true}, + AutoplanEnabled: true, + HeadRepo: models.Repo{}, + Log: logger, + Scope: statsScope, PullReqStatus: models.PullReqStatus{ Mergeable: true, }, @@ -666,6 +678,7 @@ projects: false, false, false, + valid.Autodiscover{Enabled: true}, false, false, "", @@ -802,15 +815,16 @@ projects: terraform_version: v10.0 `, expCtx: command.ProjectContext{ - ApplyCmd: "atlantis apply -p myproject_1", - ApprovePoliciesCmd: "atlantis approve_policies -p myproject_1", - BaseRepo: baseRepo, - EscapedCommentArgs: []string{`\f\l\a\g`}, - AutomergeEnabled: true, - AutoplanEnabled: true, - HeadRepo: models.Repo{}, - Log: logging.NewNoopLogger(t), - Scope: statsScope, + ApplyCmd: "atlantis apply -p myproject_1", + ApprovePoliciesCmd: "atlantis approve_policies -p myproject_1", + BaseRepo: baseRepo, + EscapedCommentArgs: []string{`\f\l\a\g`}, + AutomergeEnabled: true, + AutodiscoverEnabled: valid.Autodiscover{Enabled: true}, + AutoplanEnabled: true, + HeadRepo: models.Repo{}, + Log: logging.NewNoopLogger(t), + Scope: statsScope, PullReqStatus: models.PullReqStatus{ Mergeable: true, }, @@ -881,6 +895,7 @@ projects: false, true, false, + valid.Autodiscover{Enabled: true}, false, false, "", @@ -983,15 +998,16 @@ repos: `, repoCfg: "", expCtx: command.ProjectContext{ - ApplyCmd: "atlantis apply -d project1 -w myworkspace", - ApprovePoliciesCmd: "atlantis approve_policies -d project1 -w myworkspace", - BaseRepo: baseRepo, - EscapedCommentArgs: []string{`\f\l\a\g`}, - AutomergeEnabled: false, - AutoplanEnabled: true, - HeadRepo: models.Repo{}, - Log: logger, - Scope: statsScope, + ApplyCmd: "atlantis apply -d project1 -w myworkspace", + ApprovePoliciesCmd: "atlantis approve_policies -d project1 -w myworkspace", + BaseRepo: baseRepo, + EscapedCommentArgs: []string{`\f\l\a\g`}, + AutomergeEnabled: false, + AutodiscoverEnabled: valid.Autodiscover{Enabled: true}, + AutoplanEnabled: true, + HeadRepo: models.Repo{}, + Log: logger, + Scope: statsScope, PullReqStatus: models.PullReqStatus{ Mergeable: true, }, @@ -1029,6 +1045,8 @@ workflows: repoCfg: ` version: 3 automerge: true +autodiscover: + enabled: true projects: - dir: project1 workspace: myworkspace @@ -1045,15 +1063,16 @@ workflows: - policy_check `, expCtx: command.ProjectContext{ - ApplyCmd: "atlantis apply -d project1 -w myworkspace", - ApprovePoliciesCmd: "atlantis approve_policies -d project1 -w myworkspace", - BaseRepo: baseRepo, - EscapedCommentArgs: []string{`\f\l\a\g`}, - AutomergeEnabled: true, - AutoplanEnabled: true, - HeadRepo: models.Repo{}, - Log: logger, - Scope: statsScope, + ApplyCmd: "atlantis apply -d project1 -w myworkspace", + ApprovePoliciesCmd: "atlantis approve_policies -d project1 -w myworkspace", + BaseRepo: baseRepo, + EscapedCommentArgs: []string{`\f\l\a\g`}, + AutomergeEnabled: true, + AutodiscoverEnabled: valid.Autodiscover{Enabled: true}, + AutoplanEnabled: true, + HeadRepo: models.Repo{}, + Log: logger, + Scope: statsScope, PullReqStatus: models.PullReqStatus{ Mergeable: true, }, @@ -1130,6 +1149,7 @@ workflows: false, false, false, + valid.Autodiscover{Enabled: true}, false, false, "", @@ -1286,6 +1306,7 @@ projects: false, false, false, + valid.Autodiscover{Enabled: true}, false, false, "", diff --git a/server/events/project_command_builder_test.go b/server/events/project_command_builder_test.go index 6a3e73798d..57d519a8b4 100644 --- a/server/events/project_command_builder_test.go +++ b/server/events/project_command_builder_test.go @@ -26,6 +26,7 @@ var defaultUserConfig = struct { SkipCloneNoChanges bool EnableRegExpCmd bool EnableAutoMerge bool + EnableAutoDiscover valid.Autodiscover EnableParallelPlan bool EnableParallelApply bool AutoDetectModuleFiles string @@ -187,6 +188,7 @@ projects: userConfig.SkipCloneNoChanges, userConfig.EnableRegExpCmd, userConfig.EnableAutoMerge, + userConfig.EnableAutoDiscover, userConfig.EnableParallelPlan, userConfig.EnableParallelApply, userConfig.AutoDetectModuleFiles, @@ -232,6 +234,7 @@ func TestDefaultProjectCommandBuilder_BuildSinglePlanApplyCommand(t *testing.T) ExpErr string ExpApplyReqs []string EnableAutoMergeUserCfg bool + EnableAutoDiscoverUserCfg valid.Autodiscover EnableParallelPlanUserCfg bool EnableParallelApplyUserCfg bool ExpAutoMerge bool @@ -543,6 +546,7 @@ projects: userConfig.SkipCloneNoChanges, userConfig.EnableRegExpCmd, c.EnableAutoMergeUserCfg, + c.EnableAutoDiscoverUserCfg, c.EnableParallelPlanUserCfg, c.EnableParallelApplyUserCfg, userConfig.AutoDetectModuleFiles, @@ -732,6 +736,7 @@ projects: userConfig.SkipCloneNoChanges, userConfig.EnableRegExpCmd, userConfig.EnableAutoMerge, + userConfig.EnableAutoDiscover, userConfig.EnableParallelPlan, userConfig.EnableParallelApply, userConfig.AutoDetectModuleFiles, @@ -770,6 +775,7 @@ func TestDefaultProjectCommandBuilder_BuildPlanCommands(t *testing.T) { RepoRelDir string Workspace string Automerge bool + Autodiscover valid.Autodiscover ExpParallelPlan bool ExpParallelApply bool } @@ -913,6 +919,60 @@ parallel_apply: false }, }, }, + "no projects and autodiscover is true in atlantis.yaml": { + DirStructure: map[string]interface{}{ + "project1": map[string]interface{}{ + "main.tf": nil, + }, + "project2": map[string]interface{}{ + "main.tf": nil, + }, + }, + AtlantisYAML: ` +version: 3 +automerge: true +autodiscover: + enabled: true +parallel_plan: true +parallel_apply: true +`, + ModifiedFiles: []string{"project1/main.tf", "project2/main.tf"}, + Exp: []expCtxFields{ + { + ProjectName: "", + RepoRelDir: "project1", + Workspace: "default", + Automerge: true, + Autodiscover: valid.Autodiscover{Enabled: true}, + ExpParallelApply: true, + ExpParallelPlan: true, + }, + { + ProjectName: "", + RepoRelDir: "project2", + Workspace: "default", + Automerge: true, + Autodiscover: valid.Autodiscover{Enabled: true}, + ExpParallelApply: true, + ExpParallelPlan: true, + }, + }, + }, + "no projects and the autodiscover is false atlantis.yaml": { + DirStructure: map[string]interface{}{ + "main.tf": nil, + }, + AtlantisYAML: ` +version: 3 +automerge: true +autodiscover: + enabled: false +parallel_plan: true +parallel_apply: true +`, + ModifiedFiles: []string{"project1/main.tf", "project2/main.tf"}, + Exp: []expCtxFields{}, + }, "no modified files": { DirStructure: map[string]interface{}{ "main.tf": nil, @@ -1000,6 +1060,7 @@ projects: userConfig.SkipCloneNoChanges, userConfig.EnableRegExpCmd, userConfig.EnableAutoMerge, + userConfig.EnableAutoDiscover, c.ParallelPlanEnabledUserCfg, c.ParallelApplyEnabledUserCfg, userConfig.AutoDetectModuleFiles, @@ -1021,7 +1082,7 @@ projects: RepoRelDir: "", Flags: nil, Name: command.Plan, - Verbose: false, + Verbose: true, Workspace: "", ProjectName: "", }) @@ -1104,6 +1165,7 @@ func TestDefaultProjectCommandBuilder_BuildMultiApply(t *testing.T) { userConfig.SkipCloneNoChanges, userConfig.EnableRegExpCmd, userConfig.EnableAutoMerge, + userConfig.EnableAutoDiscover, userConfig.EnableParallelPlan, userConfig.EnableParallelApply, userConfig.AutoDetectModuleFiles, @@ -1199,6 +1261,7 @@ projects: userConfig.SkipCloneNoChanges, userConfig.EnableRegExpCmd, userConfig.EnableAutoMerge, + userConfig.EnableAutoDiscover, userConfig.EnableParallelPlan, userConfig.EnableParallelApply, userConfig.AutoDetectModuleFiles, @@ -1289,6 +1352,7 @@ func TestDefaultProjectCommandBuilder_EscapeArgs(t *testing.T) { userConfig.SkipCloneNoChanges, userConfig.EnableRegExpCmd, userConfig.EnableAutoMerge, + userConfig.EnableAutoDiscover, userConfig.EnableParallelPlan, userConfig.EnableParallelApply, userConfig.AutoDetectModuleFiles, @@ -1460,6 +1524,7 @@ projects: userConfig.SkipCloneNoChanges, userConfig.EnableRegExpCmd, userConfig.EnableAutoMerge, + userConfig.EnableAutoDiscover, userConfig.EnableParallelPlan, userConfig.EnableParallelApply, userConfig.AutoDetectModuleFiles, @@ -1561,6 +1626,7 @@ parallel_plan: true`, userConfig.SkipCloneNoChanges, userConfig.EnableRegExpCmd, userConfig.EnableAutoMerge, + userConfig.EnableAutoDiscover, userConfig.EnableParallelPlan, userConfig.EnableParallelApply, userConfig.AutoDetectModuleFiles, @@ -1631,6 +1697,7 @@ func TestDefaultProjectCommandBuilder_WithPolicyCheckEnabled_BuildAutoplanComman userConfig.SkipCloneNoChanges, userConfig.EnableRegExpCmd, userConfig.EnableAutoMerge, + userConfig.EnableAutoDiscover, userConfig.EnableParallelPlan, userConfig.EnableParallelApply, userConfig.AutoDetectModuleFiles, @@ -1723,6 +1790,7 @@ func TestDefaultProjectCommandBuilder_BuildVersionCommand(t *testing.T) { userConfig.SkipCloneNoChanges, userConfig.EnableRegExpCmd, userConfig.EnableAutoMerge, + userConfig.EnableAutoDiscover, userConfig.EnableParallelPlan, userConfig.EnableParallelApply, userConfig.AutoDetectModuleFiles, @@ -1854,6 +1922,7 @@ func TestDefaultProjectCommandBuilder_BuildPlanCommands_Single_With_RestrictFile userConfig.SkipCloneNoChanges, userConfig.EnableRegExpCmd, userConfig.EnableAutoMerge, + userConfig.EnableAutoDiscover, userConfig.EnableParallelPlan, userConfig.EnableParallelApply, userConfig.AutoDetectModuleFiles, @@ -1965,6 +2034,7 @@ func TestDefaultProjectCommandBuilder_BuildPlanCommands_with_IncludeGitUntracked userConfig.SkipCloneNoChanges, userConfig.EnableRegExpCmd, userConfig.EnableAutoMerge, + userConfig.EnableAutoDiscover, userConfig.EnableParallelPlan, userConfig.EnableParallelApply, userConfig.AutoDetectModuleFiles, diff --git a/server/events/project_command_context_builder.go b/server/events/project_command_context_builder.go index 16714f841a..0bd4a4c712 100644 --- a/server/events/project_command_context_builder.go +++ b/server/events/project_command_context_builder.go @@ -38,7 +38,7 @@ type ProjectCommandContextBuilder interface { prjCfg valid.MergedProjectCfg, commentFlags []string, repoDir string, - automerge, parallelApply, parallelPlan, verbose, abortOnExcecutionOrderFail bool, terraformClient terraform.Client, + automerge bool, autodiscover valid.Autodiscover, parallelApply, parallelPlan, verbose, abortOnExcecutionOrderFail bool, terraformClient terraform.Client, ) []command.ProjectContext } @@ -58,13 +58,12 @@ func (cb *CommandScopedStatsProjectCommandContextBuilder) BuildProjectContext( prjCfg valid.MergedProjectCfg, commentFlags []string, repoDir string, - automerge, parallelApply, parallelPlan, verbose, abortOnExcecutionOrderFail bool, - terraformClient terraform.Client, + automerge bool, autodiscover valid.Autodiscover, parallelApply, parallelPlan, verbose, abortOnExcecutionOrderFail bool, terraformClient terraform.Client, ) (projectCmds []command.ProjectContext) { cb.ProjectCounter.Inc(1) cmds := cb.ProjectCommandContextBuilder.BuildProjectContext( - ctx, cmdName, subCmdName, prjCfg, commentFlags, repoDir, automerge, parallelApply, parallelPlan, verbose, abortOnExcecutionOrderFail, terraformClient, + ctx, cmdName, subCmdName, prjCfg, commentFlags, repoDir, automerge, autodiscover, parallelApply, parallelPlan, verbose, abortOnExcecutionOrderFail, terraformClient, ) projectCmds = []command.ProjectContext{} @@ -92,8 +91,7 @@ func (cb *DefaultProjectCommandContextBuilder) BuildProjectContext( prjCfg valid.MergedProjectCfg, commentFlags []string, repoDir string, - automerge, parallelApply, parallelPlan, verbose, abortOnExcecutionOrderFail bool, - terraformClient terraform.Client, + automerge bool, autodiscover valid.Autodiscover, parallelApply, parallelPlan, verbose, abortOnExcecutionOrderFail bool, terraformClient terraform.Client, ) (projectCmds []command.ProjectContext) { ctx.Log.Debug("Building project command context for %s", cmdName) @@ -138,6 +136,7 @@ func (cb *DefaultProjectCommandContextBuilder) BuildProjectContext( prjCfg.PolicySets, escapeArgs(commentFlags), automerge, + autodiscover, parallelApply, parallelPlan, verbose, @@ -163,8 +162,7 @@ func (cb *PolicyCheckProjectCommandContextBuilder) BuildProjectContext( prjCfg valid.MergedProjectCfg, commentFlags []string, repoDir string, - automerge, parallelApply, parallelPlan, verbose, abortOnExcecutionOrderFail bool, - terraformClient terraform.Client, + automerge bool, autodiscover valid.Autodiscover, parallelApply, parallelPlan, verbose, abortOnExcecutionOrderFail bool, terraformClient terraform.Client, ) (projectCmds []command.ProjectContext) { if prjCfg.PolicyCheck { ctx.Log.Debug("PolicyChecks are enabled") @@ -187,6 +185,7 @@ func (cb *PolicyCheckProjectCommandContextBuilder) BuildProjectContext( commentFlags, repoDir, automerge, + autodiscover, parallelApply, parallelPlan, verbose, @@ -209,6 +208,7 @@ func (cb *PolicyCheckProjectCommandContextBuilder) BuildProjectContext( prjCfg.PolicySets, escapeArgs(commentFlags), automerge, + autodiscover, parallelApply, parallelPlan, verbose, @@ -233,6 +233,7 @@ func newProjectCommandContext(ctx *command.Context, policySets valid.PolicySets, escapedCommentArgs []string, automergeEnabled bool, + autodiscoverEnabled valid.Autodiscover, parallelApplyEnabled bool, parallelPlanEnabled bool, verbose bool, @@ -269,6 +270,7 @@ func newProjectCommandContext(ctx *command.Context, BaseRepo: ctx.Pull.BaseRepo, EscapedCommentArgs: escapedCommentArgs, AutomergeEnabled: automergeEnabled, + AutodiscoverEnabled: autodiscoverEnabled, DeleteSourceBranchOnMerge: projCfg.DeleteSourceBranchOnMerge, RepoLocking: projCfg.RepoLocking, CustomPolicyCheck: projCfg.CustomPolicyCheck, diff --git a/server/events/project_command_context_builder_test.go b/server/events/project_command_context_builder_test.go index 8bee1d9fb0..859bcaa306 100644 --- a/server/events/project_command_context_builder_test.go +++ b/server/events/project_command_context_builder_test.go @@ -62,7 +62,7 @@ func TestProjectCommandContextBuilder_PullStatus(t *testing.T) { }, } - result := subject.BuildProjectContext(commandCtx, command.Plan, "", projCfg, []string{}, "some/dir", false, false, false, false, false, terraformClient) + result := subject.BuildProjectContext(commandCtx, command.Plan, "", projCfg, []string{}, "some/dir", false, valid.Autodiscover{Enabled: true}, false, false, false, false, terraformClient) assert.Equal(t, models.ErroredPolicyCheckStatus, result[0].ProjectPlanStatus) }) @@ -81,7 +81,7 @@ func TestProjectCommandContextBuilder_PullStatus(t *testing.T) { }, } - result := subject.BuildProjectContext(commandCtx, command.Plan, "", projCfg, []string{}, "some/dir", false, false, false, false, false, terraformClient) + result := subject.BuildProjectContext(commandCtx, command.Plan, "", projCfg, []string{}, "some/dir", false, valid.Autodiscover{Enabled: true}, false, false, false, false, terraformClient) assert.Equal(t, models.ErroredPolicyCheckStatus, result[0].ProjectPlanStatus) }) @@ -101,7 +101,7 @@ func TestProjectCommandContextBuilder_PullStatus(t *testing.T) { }, } - result := subject.BuildProjectContext(commandCtx, command.Plan, "", projCfg, []string{}, "some/dir", false, true, false, false, false, terraformClient) + result := subject.BuildProjectContext(commandCtx, command.Plan, "", projCfg, []string{}, "some/dir", false, valid.Autodiscover{Enabled: true}, true, false, false, false, terraformClient) assert.True(t, result[0].ParallelApplyEnabled) assert.False(t, result[0].ParallelPlanEnabled) @@ -122,7 +122,7 @@ func TestProjectCommandContextBuilder_PullStatus(t *testing.T) { }, } - result := subject.BuildProjectContext(commandCtx, command.Plan, "", projCfg, []string{}, "some/dir", false, false, false, false, true, terraformClient) + result := subject.BuildProjectContext(commandCtx, command.Plan, "", projCfg, []string{}, "some/dir", false, valid.Autodiscover{Enabled: true}, false, false, false, true, terraformClient) assert.True(t, result[0].AbortOnExcecutionOrderFail) }) diff --git a/server/server.go b/server/server.go index 6f80cb420f..bb62c6e261 100644 --- a/server/server.go +++ b/server/server.go @@ -590,6 +590,7 @@ func NewServer(userConfig UserConfig, config Config) (*Server, error) { userConfig.SkipCloneNoChanges, userConfig.EnableRegExpCmd, userConfig.Automerge, + userConfig.Autodiscover, userConfig.ParallelPlan, userConfig.ParallelApply, userConfig.AutoplanModulesFromProjects, diff --git a/server/user_config.go b/server/user_config.go index 49e3ed6fba..2c69b9abed 100644 --- a/server/user_config.go +++ b/server/user_config.go @@ -3,6 +3,7 @@ package server import ( "strings" + "github.com/runatlantis/atlantis/server/core/config/valid" "github.com/runatlantis/atlantis/server/events/command" "github.com/runatlantis/atlantis/server/logging" ) @@ -11,39 +12,40 @@ import ( // The mapstructure tags correspond to flags in cmd/server.go and are used when // the config is parsed from a YAML file. type UserConfig struct { - AllowForkPRs bool `mapstructure:"allow-fork-prs"` - AllowRepoConfig bool `mapstructure:"allow-repo-config"` - AllowCommands string `mapstructure:"allow-commands"` - AtlantisURL string `mapstructure:"atlantis-url"` - Automerge bool `mapstructure:"automerge"` - AutoplanFileList string `mapstructure:"autoplan-file-list"` - AutoplanModules bool `mapstructure:"autoplan-modules"` - AutoplanModulesFromProjects string `mapstructure:"autoplan-modules-from-projects"` - AzureDevopsToken string `mapstructure:"azuredevops-token"` - AzureDevopsUser string `mapstructure:"azuredevops-user"` - AzureDevopsWebhookPassword string `mapstructure:"azuredevops-webhook-password"` - AzureDevopsWebhookUser string `mapstructure:"azuredevops-webhook-user"` - AzureDevOpsHostname string `mapstructure:"azuredevops-hostname"` - BitbucketBaseURL string `mapstructure:"bitbucket-base-url"` - BitbucketToken string `mapstructure:"bitbucket-token"` - BitbucketUser string `mapstructure:"bitbucket-user"` - BitbucketWebhookSecret string `mapstructure:"bitbucket-webhook-secret"` - CheckoutDepth int `mapstructure:"checkout-depth"` - CheckoutStrategy string `mapstructure:"checkout-strategy"` - DataDir string `mapstructure:"data-dir"` - DisableApplyAll bool `mapstructure:"disable-apply-all"` - DisableApply bool `mapstructure:"disable-apply"` - DisableAutoplan bool `mapstructure:"disable-autoplan"` - DisableAutoplanLabel string `mapstructure:"disable-autoplan-label"` - DisableMarkdownFolding bool `mapstructure:"disable-markdown-folding"` - DisableRepoLocking bool `mapstructure:"disable-repo-locking"` - DisableUnlockLabel string `mapstructure:"disable-unlock-label"` - DiscardApprovalOnPlanFlag bool `mapstructure:"discard-approval-on-plan"` - EmojiReaction string `mapstructure:"emoji-reaction"` - EnablePolicyChecksFlag bool `mapstructure:"enable-policy-checks"` - EnableRegExpCmd bool `mapstructure:"enable-regexp-cmd"` - EnableDiffMarkdownFormat bool `mapstructure:"enable-diff-markdown-format"` - ExecutableName string `mapstructure:"executable-name"` + AllowForkPRs bool `mapstructure:"allow-fork-prs"` + AllowRepoConfig bool `mapstructure:"allow-repo-config"` + AllowCommands string `mapstructure:"allow-commands"` + AtlantisURL string `mapstructure:"atlantis-url"` + Automerge bool `mapstructure:"automerge"` + Autodiscover valid.Autodiscover `mapstructure:"autodiscover"` + AutoplanFileList string `mapstructure:"autoplan-file-list"` + AutoplanModules bool `mapstructure:"autoplan-modules"` + AutoplanModulesFromProjects string `mapstructure:"autoplan-modules-from-projects"` + AzureDevopsToken string `mapstructure:"azuredevops-token"` + AzureDevopsUser string `mapstructure:"azuredevops-user"` + AzureDevopsWebhookPassword string `mapstructure:"azuredevops-webhook-password"` + AzureDevopsWebhookUser string `mapstructure:"azuredevops-webhook-user"` + AzureDevOpsHostname string `mapstructure:"azuredevops-hostname"` + BitbucketBaseURL string `mapstructure:"bitbucket-base-url"` + BitbucketToken string `mapstructure:"bitbucket-token"` + BitbucketUser string `mapstructure:"bitbucket-user"` + BitbucketWebhookSecret string `mapstructure:"bitbucket-webhook-secret"` + CheckoutDepth int `mapstructure:"checkout-depth"` + CheckoutStrategy string `mapstructure:"checkout-strategy"` + DataDir string `mapstructure:"data-dir"` + DisableApplyAll bool `mapstructure:"disable-apply-all"` + DisableApply bool `mapstructure:"disable-apply"` + DisableAutoplan bool `mapstructure:"disable-autoplan"` + DisableAutoplanLabel string `mapstructure:"disable-autoplan-label"` + DisableMarkdownFolding bool `mapstructure:"disable-markdown-folding"` + DisableRepoLocking bool `mapstructure:"disable-repo-locking"` + DisableUnlockLabel string `mapstructure:"disable-unlock-label"` + DiscardApprovalOnPlanFlag bool `mapstructure:"discard-approval-on-plan"` + EmojiReaction string `mapstructure:"emoji-reaction"` + EnablePolicyChecksFlag bool `mapstructure:"enable-policy-checks"` + EnableRegExpCmd bool `mapstructure:"enable-regexp-cmd"` + EnableDiffMarkdownFormat bool `mapstructure:"enable-diff-markdown-format"` + ExecutableName string `mapstructure:"executable-name"` // Fail and do not run the Atlantis command request if any of the pre workflow hooks error. FailOnPreWorkflowHookError bool `mapstructure:"fail-on-pre-workflow-hook-error"` HideUnchangedPlanComments bool `mapstructure:"hide-unchanged-plan-comments"`