Skip to content

Commit

Permalink
Update defaultwhenmodified to include **/terragrunt.hcl (#858)
Browse files Browse the repository at this point in the history
Update defaultwhenmodified to include **/terragrunt.hcl

This allows a pre-existing TG 0.19+ project to autoplan if no when_modified is set

Closes #803
  • Loading branch information
JoshiiSinfield authored and lkysow committed Jan 20, 2020
1 parent 8eb5bb8 commit e78cdd9
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 28 deletions.
50 changes: 36 additions & 14 deletions server/events/yaml/parser_validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ projects:
WorkflowName: nil,
TerraformVersion: nil,
Autoplan: valid.Autoplan{
WhenModified: []string{"**/*.tf*"},
WhenModified: []string{"**/*.tf*", "**/terragrunt.hcl"},
Enabled: true,
},
ApplyRequirements: nil,
Expand All @@ -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*"]
Expand Down Expand Up @@ -253,7 +275,7 @@ projects:
Dir: ".",
Workspace: "default",
Autoplan: valid.Autoplan{
WhenModified: []string{"**/*.tf*"},
WhenModified: []string{"**/*.tf*", "**/terragrunt.hcl"},
Enabled: true,
},
},
Expand All @@ -276,7 +298,7 @@ workflows: ~
Dir: ".",
Workspace: "default",
Autoplan: valid.Autoplan{
WhenModified: []string{"**/*.tf*"},
WhenModified: []string{"**/*.tf*", "**/terragrunt.hcl"},
Enabled: true,
},
},
Expand Down Expand Up @@ -304,7 +326,7 @@ workflows:
Dir: ".",
Workspace: "default",
Autoplan: valid.Autoplan{
WhenModified: []string{"**/*.tf*"},
WhenModified: []string{"**/*.tf*", "**/terragrunt.hcl"},
Enabled: true,
},
},
Expand Down Expand Up @@ -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"},
Expand Down Expand Up @@ -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"},
Expand Down Expand Up @@ -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"},
Expand Down Expand Up @@ -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"},
Expand Down Expand Up @@ -567,7 +589,7 @@ projects:
Dir: ".",
Workspace: "workspace",
Autoplan: valid.Autoplan{
WhenModified: []string{"**/*.tf*"},
WhenModified: []string{"**/*.tf*", "**/terragrunt.hcl"},
Enabled: true,
},
},
Expand All @@ -576,7 +598,7 @@ projects:
Dir: ".",
Workspace: "workspace",
Autoplan: valid.Autoplan{
WhenModified: []string{"**/*.tf*"},
WhenModified: []string{"**/*.tf*", "**/terragrunt.hcl"},
Enabled: true,
},
},
Expand Down Expand Up @@ -608,7 +630,7 @@ workflows:
Dir: ".",
Workspace: "default",
Autoplan: valid.Autoplan{
WhenModified: []string{"**/*.tf*"},
WhenModified: []string{"**/*.tf*", "**/terragrunt.hcl"},
Enabled: true,
},
},
Expand Down Expand Up @@ -670,7 +692,7 @@ workflows:
Dir: ".",
Workspace: "default",
Autoplan: valid.Autoplan{
WhenModified: []string{"**/*.tf*"},
WhenModified: []string{"**/*.tf*", "**/terragrunt.hcl"},
Enabled: true,
},
},
Expand Down Expand Up @@ -728,7 +750,7 @@ workflows:
Dir: ".",
Workspace: "default",
Autoplan: valid.Autoplan{
WhenModified: []string{"**/*.tf*"},
WhenModified: []string{"**/*.tf*", "**/terragrunt.hcl"},
Enabled: true,
},
},
Expand Down Expand Up @@ -782,7 +804,7 @@ workflows:
Dir: ".",
Workspace: "default",
Autoplan: valid.Autoplan{
WhenModified: []string{"**/*.tf*"},
WhenModified: []string{"**/*.tf*", "**/terragrunt.hcl"},
Enabled: true,
},
},
Expand Down
10 changes: 6 additions & 4 deletions server/events/yaml/raw/autoplan.go
Original file line number Diff line number Diff line change
@@ -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"`
Expand All @@ -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
}
Expand All @@ -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,
}
}
6 changes: 3 additions & 3 deletions server/events/yaml/raw/autoplan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
},
},
{
Expand All @@ -129,7 +129,7 @@ func TestAutoplan_ToValid(t *testing.T) {
},
exp: valid.Autoplan{
Enabled: false,
WhenModified: []string{"**/*.tf*"},
WhenModified: []string{"**/*.tf*", "**/terragrunt.hcl"},
},
},
{
Expand All @@ -139,7 +139,7 @@ func TestAutoplan_ToValid(t *testing.T) {
},
exp: valid.Autoplan{
Enabled: true,
WhenModified: []string{"**/*.tf*"},
WhenModified: []string{"**/*.tf*", "**/terragrunt.hcl"},
},
},
}
Expand Down
12 changes: 6 additions & 6 deletions server/events/yaml/raw/project_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
},
},
Expand All @@ -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,
},
},
Expand Down Expand Up @@ -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,
},
},
Expand All @@ -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,
},
},
Expand Down Expand Up @@ -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,
},
},
Expand Down
2 changes: 1 addition & 1 deletion server/events/yaml/raw/repo_cfg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
},
Expand Down

0 comments on commit e78cdd9

Please sign in to comment.