diff --git a/server/events/yaml/parser_validator_test.go b/server/events/yaml/parser_validator_test.go index bc3f2e42a1..11df9f9b1b 100644 --- a/server/events/yaml/parser_validator_test.go +++ b/server/events/yaml/parser_validator_test.go @@ -206,7 +206,7 @@ projects: WorkflowName: nil, TerraformVersion: nil, Autoplan: valid.Autoplan{ - WhenModified: []string{"**/*.tf*"}, + WhenModified: []string{"**/*.tf*", "**/terragrunt.hcl"}, Enabled: true, }, ApplyRequirements: nil, @@ -220,6 +220,28 @@ projects: input: ` version: 3 projects: +- dir: "." +`, + exp: valid.RepoCfg{ + Version: 3, + Projects: []valid.Project{ + { + Dir: ".", + Workspace: "default", + Autoplan: valid.Autoplan{ + WhenModified: []string{"**/*.tf*", "**/terragrunt.hcl"}, + Enabled: true, + }, + }, + }, + Workflows: make(map[string]valid.Workflow), + }, + }, + { + description: "autoplan should be enabled by default if only when_modified set", + input: ` +version: 3 +projects: - dir: "." autoplan: when_modified: ["**/*.tf*"] @@ -253,7 +275,7 @@ projects: Dir: ".", Workspace: "default", Autoplan: valid.Autoplan{ - WhenModified: []string{"**/*.tf*"}, + WhenModified: []string{"**/*.tf*", "**/terragrunt.hcl"}, Enabled: true, }, }, @@ -276,7 +298,7 @@ workflows: ~ Dir: ".", Workspace: "default", Autoplan: valid.Autoplan{ - WhenModified: []string{"**/*.tf*"}, + WhenModified: []string{"**/*.tf*", "**/terragrunt.hcl"}, Enabled: true, }, }, @@ -304,7 +326,7 @@ workflows: Dir: ".", Workspace: "default", Autoplan: valid.Autoplan{ - WhenModified: []string{"**/*.tf*"}, + WhenModified: []string{"**/*.tf*", "**/terragrunt.hcl"}, Enabled: true, }, }, @@ -339,7 +361,7 @@ workflows: WorkflowName: String("myworkflow"), TerraformVersion: tfVersion, Autoplan: valid.Autoplan{ - WhenModified: []string{"**/*.tf*"}, + WhenModified: []string{"**/*.tf*", "**/terragrunt.hcl"}, Enabled: true, }, ApplyRequirements: []string{"approved"}, @@ -377,7 +399,7 @@ workflows: WorkflowName: String("myworkflow"), TerraformVersion: tfVersion, Autoplan: valid.Autoplan{ - WhenModified: []string{"**/*.tf*"}, + WhenModified: []string{"**/*.tf*", "**/terragrunt.hcl"}, Enabled: false, }, ApplyRequirements: []string{"approved"}, @@ -415,7 +437,7 @@ workflows: WorkflowName: String("myworkflow"), TerraformVersion: tfVersion, Autoplan: valid.Autoplan{ - WhenModified: []string{"**/*.tf*"}, + WhenModified: []string{"**/*.tf*", "**/terragrunt.hcl"}, Enabled: false, }, ApplyRequirements: []string{"mergeable"}, @@ -453,7 +475,7 @@ workflows: WorkflowName: String("myworkflow"), TerraformVersion: tfVersion, Autoplan: valid.Autoplan{ - WhenModified: []string{"**/*.tf*"}, + WhenModified: []string{"**/*.tf*", "**/terragrunt.hcl"}, Enabled: false, }, ApplyRequirements: []string{"mergeable", "approved"}, @@ -567,7 +589,7 @@ projects: Dir: ".", Workspace: "workspace", Autoplan: valid.Autoplan{ - WhenModified: []string{"**/*.tf*"}, + WhenModified: []string{"**/*.tf*", "**/terragrunt.hcl"}, Enabled: true, }, }, @@ -576,7 +598,7 @@ projects: Dir: ".", Workspace: "workspace", Autoplan: valid.Autoplan{ - WhenModified: []string{"**/*.tf*"}, + WhenModified: []string{"**/*.tf*", "**/terragrunt.hcl"}, Enabled: true, }, }, @@ -608,7 +630,7 @@ workflows: Dir: ".", Workspace: "default", Autoplan: valid.Autoplan{ - WhenModified: []string{"**/*.tf*"}, + WhenModified: []string{"**/*.tf*", "**/terragrunt.hcl"}, Enabled: true, }, }, @@ -670,7 +692,7 @@ workflows: Dir: ".", Workspace: "default", Autoplan: valid.Autoplan{ - WhenModified: []string{"**/*.tf*"}, + WhenModified: []string{"**/*.tf*", "**/terragrunt.hcl"}, Enabled: true, }, }, @@ -728,7 +750,7 @@ workflows: Dir: ".", Workspace: "default", Autoplan: valid.Autoplan{ - WhenModified: []string{"**/*.tf*"}, + WhenModified: []string{"**/*.tf*", "**/terragrunt.hcl"}, Enabled: true, }, }, @@ -782,7 +804,7 @@ workflows: Dir: ".", Workspace: "default", Autoplan: valid.Autoplan{ - WhenModified: []string{"**/*.tf*"}, + WhenModified: []string{"**/*.tf*", "**/terragrunt.hcl"}, Enabled: true, }, }, diff --git a/server/events/yaml/raw/autoplan.go b/server/events/yaml/raw/autoplan.go index 49b0a95eab..33f0b1fa1a 100644 --- a/server/events/yaml/raw/autoplan.go +++ b/server/events/yaml/raw/autoplan.go @@ -1,10 +1,12 @@ package raw -import "github.com/runatlantis/atlantis/server/events/yaml/valid" +import ( + "github.com/runatlantis/atlantis/server/events/yaml/valid" +) // DefaultAutoPlanWhenModified is the default element in the when_modified // list if none is defined. -const DefaultAutoPlanWhenModified = "**/*.tf*" +var DefaultAutoPlanWhenModified = []string{"**/*.tf*", "**/terragrunt.hcl"} type Autoplan struct { WhenModified []string `yaml:"when_modified,omitempty"` @@ -14,7 +16,7 @@ type Autoplan struct { func (a Autoplan) ToValid() valid.Autoplan { var v valid.Autoplan if a.WhenModified == nil { - v.WhenModified = []string{DefaultAutoPlanWhenModified} + v.WhenModified = DefaultAutoPlanWhenModified } else { v.WhenModified = a.WhenModified } @@ -35,7 +37,7 @@ func (a Autoplan) Validate() error { // DefaultAutoPlan returns the default autoplan config. func DefaultAutoPlan() valid.Autoplan { return valid.Autoplan{ - WhenModified: []string{DefaultAutoPlanWhenModified}, + WhenModified: DefaultAutoPlanWhenModified, Enabled: valid.DefaultAutoPlanEnabled, } } diff --git a/server/events/yaml/raw/autoplan_test.go b/server/events/yaml/raw/autoplan_test.go index 4e29007c91..66744340df 100644 --- a/server/events/yaml/raw/autoplan_test.go +++ b/server/events/yaml/raw/autoplan_test.go @@ -109,7 +109,7 @@ func TestAutoplan_ToValid(t *testing.T) { input: raw.Autoplan{}, exp: valid.Autoplan{ Enabled: true, - WhenModified: []string{"**/*.tf*"}, + WhenModified: []string{"**/*.tf*", "**/terragrunt.hcl"}, }, }, { @@ -129,7 +129,7 @@ func TestAutoplan_ToValid(t *testing.T) { }, exp: valid.Autoplan{ Enabled: false, - WhenModified: []string{"**/*.tf*"}, + WhenModified: []string{"**/*.tf*", "**/terragrunt.hcl"}, }, }, { @@ -139,7 +139,7 @@ func TestAutoplan_ToValid(t *testing.T) { }, exp: valid.Autoplan{ Enabled: true, - WhenModified: []string{"**/*.tf*"}, + WhenModified: []string{"**/*.tf*", "**/terragrunt.hcl"}, }, }, } diff --git a/server/events/yaml/raw/project_test.go b/server/events/yaml/raw/project_test.go index 626f09b54f..c11580bbcc 100644 --- a/server/events/yaml/raw/project_test.go +++ b/server/events/yaml/raw/project_test.go @@ -231,7 +231,7 @@ func TestProject_ToValid(t *testing.T) { WorkflowName: nil, TerraformVersion: nil, Autoplan: valid.Autoplan{ - WhenModified: []string{"**/*.tf*"}, + WhenModified: []string{"**/*.tf*", "**/terragrunt.hcl"}, Enabled: true, }, ApplyRequirements: nil, @@ -276,7 +276,7 @@ func TestProject_ToValid(t *testing.T) { Workspace: "default", TerraformVersion: tfVersionPointEleven, Autoplan: valid.Autoplan{ - WhenModified: []string{"**/*.tf*"}, + WhenModified: []string{"**/*.tf*", "**/terragrunt.hcl"}, Enabled: true, }, }, @@ -291,7 +291,7 @@ func TestProject_ToValid(t *testing.T) { Dir: ".", Workspace: "default", Autoplan: valid.Autoplan{ - WhenModified: []string{"**/*.tf*"}, + WhenModified: []string{"**/*.tf*", "**/terragrunt.hcl"}, Enabled: true, }, }, @@ -319,7 +319,7 @@ func TestProject_ToValid(t *testing.T) { Dir: "mydir", Workspace: "default", Autoplan: valid.Autoplan{ - WhenModified: []string{"**/*.tf*"}, + WhenModified: []string{"**/*.tf*", "**/terragrunt.hcl"}, Enabled: true, }, }, @@ -334,7 +334,7 @@ func TestProject_ToValid(t *testing.T) { Dir: "mydir", Workspace: "default", Autoplan: valid.Autoplan{ - WhenModified: []string{"**/*.tf*"}, + WhenModified: []string{"**/*.tf*", "**/terragrunt.hcl"}, Enabled: true, }, }, @@ -392,7 +392,7 @@ func TestProject_ToValid(t *testing.T) { Dir: ".", Workspace: "default", Autoplan: valid.Autoplan{ - WhenModified: []string{"**/*.tf*"}, + WhenModified: []string{"**/*.tf*", "**/terragrunt.hcl"}, Enabled: true, }, }, diff --git a/server/events/yaml/raw/repo_cfg_test.go b/server/events/yaml/raw/repo_cfg_test.go index 5d3da46d86..c199ba980b 100644 --- a/server/events/yaml/raw/repo_cfg_test.go +++ b/server/events/yaml/raw/repo_cfg_test.go @@ -355,7 +355,7 @@ func TestConfig_ToValid(t *testing.T) { Dir: "mydir", Workspace: "default", Autoplan: valid.Autoplan{ - WhenModified: []string{"**/*.tf*"}, + WhenModified: []string{"**/*.tf*", "**/terragrunt.hcl"}, Enabled: true, }, },