Skip to content

Commit

Permalink
fix: auto plan when .terraform.lock.hcl changed
Browse files Browse the repository at this point in the history
Problem

When `projects` are specified and `when_modified` is not specified via
the config file, changing `.terraform.lock.hcl` file won't trigger auto
plan. This is because the default `raw.WhenModified` does not include
`.terraform.lock.hcl`.

Note that when projects are auto detected, changing
`.terraform.lock.hcl` triggers auto plan. This is because the
`cmd.DefaultAutoplanFileList` includes `.terraform.lock.hcl`.

Solution

Include `.terraform.lock.hcl` to the default `raw.WhenModified`.
  • Loading branch information
shouichi committed Jul 5, 2023
1 parent 92703fe commit 7b7289f
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 45 deletions.
2 changes: 1 addition & 1 deletion runatlantis.io/docs/repo-level-atlantis-yaml.md
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ Atlantis supports this but requires the `name` key to be specified. See [Custom
### Autoplan
```yaml
enabled: true
when_modified: ["*.tf", "terragrunt.hcl"]
when_modified: ["*.tf", "terragrunt.hcl", ".terraform.lock.hcl"]
```
| Key | Type | Default | Required | Description |
|-----------------------|---------------|----------------|----------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
Expand Down
39 changes: 20 additions & 19 deletions server/core/config/parser_validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/hashicorp/go-version"
"github.com/runatlantis/atlantis/server/core/config"
"github.com/runatlantis/atlantis/server/core/config/raw"
"github.com/runatlantis/atlantis/server/core/config/valid"
. "github.com/runatlantis/atlantis/testing"
)
Expand Down Expand Up @@ -217,7 +218,7 @@ projects:
WorkflowName: nil,
TerraformVersion: nil,
Autoplan: valid.Autoplan{
WhenModified: []string{"**/*.tf*", "**/terragrunt.hcl"},
WhenModified: raw.DefaultAutoPlanWhenModified,
Enabled: true,
},
ApplyRequirements: nil,
Expand All @@ -240,7 +241,7 @@ projects:
Dir: ".",
Workspace: "default",
Autoplan: valid.Autoplan{
WhenModified: []string{"**/*.tf*", "**/terragrunt.hcl"},
WhenModified: raw.DefaultAutoPlanWhenModified,
Enabled: true,
},
},
Expand Down Expand Up @@ -286,7 +287,7 @@ projects:
Dir: ".",
Workspace: "default",
Autoplan: valid.Autoplan{
WhenModified: []string{"**/*.tf*", "**/terragrunt.hcl"},
WhenModified: raw.DefaultAutoPlanWhenModified,
Enabled: true,
},
},
Expand All @@ -309,7 +310,7 @@ workflows: ~
Dir: ".",
Workspace: "default",
Autoplan: valid.Autoplan{
WhenModified: []string{"**/*.tf*", "**/terragrunt.hcl"},
WhenModified: raw.DefaultAutoPlanWhenModified,
Enabled: true,
},
},
Expand Down Expand Up @@ -337,7 +338,7 @@ workflows:
Dir: ".",
Workspace: "default",
Autoplan: valid.Autoplan{
WhenModified: []string{"**/*.tf*", "**/terragrunt.hcl"},
WhenModified: raw.DefaultAutoPlanWhenModified,
Enabled: true,
},
},
Expand Down Expand Up @@ -368,7 +369,7 @@ workflows:
WorkflowName: String("myworkflow"),
TerraformVersion: tfVersion,
Autoplan: valid.Autoplan{
WhenModified: []string{"**/*.tf*", "**/terragrunt.hcl"},
WhenModified: raw.DefaultAutoPlanWhenModified,
Enabled: true,
},
ApplyRequirements: []string{"approved"},
Expand Down Expand Up @@ -402,7 +403,7 @@ workflows:
WorkflowName: String("myworkflow"),
TerraformVersion: tfVersion,
Autoplan: valid.Autoplan{
WhenModified: []string{"**/*.tf*", "**/terragrunt.hcl"},
WhenModified: raw.DefaultAutoPlanWhenModified,
Enabled: false,
},
ApplyRequirements: []string{"approved"},
Expand Down Expand Up @@ -436,7 +437,7 @@ workflows:
WorkflowName: String("myworkflow"),
TerraformVersion: tfVersion,
Autoplan: valid.Autoplan{
WhenModified: []string{"**/*.tf*", "**/terragrunt.hcl"},
WhenModified: raw.DefaultAutoPlanWhenModified,
Enabled: false,
},
ApplyRequirements: []string{"mergeable"},
Expand Down Expand Up @@ -470,7 +471,7 @@ workflows:
WorkflowName: String("myworkflow"),
TerraformVersion: tfVersion,
Autoplan: valid.Autoplan{
WhenModified: []string{"**/*.tf*", "**/terragrunt.hcl"},
WhenModified: raw.DefaultAutoPlanWhenModified,
Enabled: false,
},
ApplyRequirements: []string{"undiverged"},
Expand Down Expand Up @@ -504,7 +505,7 @@ workflows:
WorkflowName: String("myworkflow"),
TerraformVersion: tfVersion,
Autoplan: valid.Autoplan{
WhenModified: []string{"**/*.tf*", "**/terragrunt.hcl"},
WhenModified: raw.DefaultAutoPlanWhenModified,
Enabled: false,
},
ApplyRequirements: []string{"mergeable", "approved"},
Expand Down Expand Up @@ -538,7 +539,7 @@ workflows:
WorkflowName: String("myworkflow"),
TerraformVersion: tfVersion,
Autoplan: valid.Autoplan{
WhenModified: []string{"**/*.tf*", "**/terragrunt.hcl"},
WhenModified: raw.DefaultAutoPlanWhenModified,
Enabled: false,
},
ApplyRequirements: []string{"undiverged", "approved"},
Expand Down Expand Up @@ -572,7 +573,7 @@ workflows:
WorkflowName: String("myworkflow"),
TerraformVersion: tfVersion,
Autoplan: valid.Autoplan{
WhenModified: []string{"**/*.tf*", "**/terragrunt.hcl"},
WhenModified: raw.DefaultAutoPlanWhenModified,
Enabled: false,
},
ApplyRequirements: []string{"undiverged", "mergeable"},
Expand Down Expand Up @@ -606,7 +607,7 @@ workflows:
WorkflowName: String("myworkflow"),
TerraformVersion: tfVersion,
Autoplan: valid.Autoplan{
WhenModified: []string{"**/*.tf*", "**/terragrunt.hcl"},
WhenModified: raw.DefaultAutoPlanWhenModified,
Enabled: false,
},
ApplyRequirements: []string{"undiverged", "mergeable", "approved"},
Expand Down Expand Up @@ -716,7 +717,7 @@ projects:
Dir: ".",
Workspace: "workspace",
Autoplan: valid.Autoplan{
WhenModified: []string{"**/*.tf*", "**/terragrunt.hcl"},
WhenModified: raw.DefaultAutoPlanWhenModified,
Enabled: true,
},
},
Expand All @@ -725,7 +726,7 @@ projects:
Dir: ".",
Workspace: "workspace",
Autoplan: valid.Autoplan{
WhenModified: []string{"**/*.tf*", "**/terragrunt.hcl"},
WhenModified: raw.DefaultAutoPlanWhenModified,
Enabled: true,
},
},
Expand Down Expand Up @@ -767,7 +768,7 @@ workflows:
Dir: ".",
Workspace: "default",
Autoplan: valid.Autoplan{
WhenModified: []string{"**/*.tf*", "**/terragrunt.hcl"},
WhenModified: raw.DefaultAutoPlanWhenModified,
Enabled: true,
},
},
Expand Down Expand Up @@ -866,7 +867,7 @@ workflows:
Dir: ".",
Workspace: "default",
Autoplan: valid.Autoplan{
WhenModified: []string{"**/*.tf*", "**/terragrunt.hcl"},
WhenModified: raw.DefaultAutoPlanWhenModified,
Enabled: true,
},
},
Expand Down Expand Up @@ -957,7 +958,7 @@ workflows:
Dir: ".",
Workspace: "default",
Autoplan: valid.Autoplan{
WhenModified: []string{"**/*.tf*", "**/terragrunt.hcl"},
WhenModified: raw.DefaultAutoPlanWhenModified,
Enabled: true,
},
},
Expand Down Expand Up @@ -1050,7 +1051,7 @@ workflows:
Dir: ".",
Workspace: "default",
Autoplan: valid.Autoplan{
WhenModified: []string{"**/*.tf*", "**/terragrunt.hcl"},
WhenModified: raw.DefaultAutoPlanWhenModified,
Enabled: true,
},
},
Expand Down
6 changes: 5 additions & 1 deletion server/core/config/raw/autoplan.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ import (

// DefaultAutoPlanWhenModified is the default element in the when_modified
// list if none is defined.
var DefaultAutoPlanWhenModified = []string{"**/*.tf*", "**/terragrunt.hcl"}
var DefaultAutoPlanWhenModified = []string{
"**/*.tf*",
"**/terragrunt.hcl",
"**/.terraform.lock.hcl",
}

type Autoplan struct {
WhenModified []string `yaml:"when_modified,omitempty"`
Expand Down
6 changes: 3 additions & 3 deletions server/core/config/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*", "**/terragrunt.hcl"},
WhenModified: raw.DefaultAutoPlanWhenModified,
},
},
{
Expand All @@ -129,7 +129,7 @@ func TestAutoplan_ToValid(t *testing.T) {
},
exp: valid.Autoplan{
Enabled: false,
WhenModified: []string{"**/*.tf*", "**/terragrunt.hcl"},
WhenModified: raw.DefaultAutoPlanWhenModified,
},
},
{
Expand All @@ -139,7 +139,7 @@ func TestAutoplan_ToValid(t *testing.T) {
},
exp: valid.Autoplan{
Enabled: true,
WhenModified: []string{"**/*.tf*", "**/terragrunt.hcl"},
WhenModified: raw.DefaultAutoPlanWhenModified,
},
},
}
Expand Down
20 changes: 10 additions & 10 deletions server/core/config/raw/project_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ func TestProject_ToValid(t *testing.T) {
WorkflowName: nil,
TerraformVersion: nil,
Autoplan: valid.Autoplan{
WhenModified: []string{"**/*.tf*", "**/terragrunt.hcl"},
WhenModified: raw.DefaultAutoPlanWhenModified,
Enabled: true,
},
ApplyRequirements: nil,
Expand Down Expand Up @@ -396,7 +396,7 @@ func TestProject_ToValid(t *testing.T) {
Workspace: "default",
TerraformVersion: tfVersionPointEleven,
Autoplan: valid.Autoplan{
WhenModified: []string{"**/*.tf*", "**/terragrunt.hcl"},
WhenModified: raw.DefaultAutoPlanWhenModified,
Enabled: true,
},
},
Expand All @@ -411,7 +411,7 @@ func TestProject_ToValid(t *testing.T) {
Dir: ".",
Workspace: "default",
Autoplan: valid.Autoplan{
WhenModified: []string{"**/*.tf*", "**/terragrunt.hcl"},
WhenModified: raw.DefaultAutoPlanWhenModified,
Enabled: true,
},
},
Expand All @@ -425,7 +425,7 @@ func TestProject_ToValid(t *testing.T) {
Dir: "a/b/c",
Workspace: "default",
Autoplan: valid.Autoplan{
WhenModified: []string{"**/*.tf*", "**/terragrunt.hcl"},
WhenModified: raw.DefaultAutoPlanWhenModified,
Enabled: true,
},
},
Expand All @@ -439,7 +439,7 @@ func TestProject_ToValid(t *testing.T) {
Dir: "mydir",
Workspace: "default",
Autoplan: valid.Autoplan{
WhenModified: []string{"**/*.tf*", "**/terragrunt.hcl"},
WhenModified: raw.DefaultAutoPlanWhenModified,
Enabled: true,
},
},
Expand All @@ -454,7 +454,7 @@ func TestProject_ToValid(t *testing.T) {
Dir: "mydir",
Workspace: "default",
Autoplan: valid.Autoplan{
WhenModified: []string{"**/*.tf*", "**/terragrunt.hcl"},
WhenModified: raw.DefaultAutoPlanWhenModified,
Enabled: true,
},
},
Expand All @@ -468,7 +468,7 @@ func TestProject_ToValid(t *testing.T) {
Dir: ".",
Workspace: "default",
Autoplan: valid.Autoplan{
WhenModified: []string{"**/*.tf*", "**/terragrunt.hcl"},
WhenModified: raw.DefaultAutoPlanWhenModified,
Enabled: true,
},
},
Expand All @@ -482,7 +482,7 @@ func TestProject_ToValid(t *testing.T) {
Dir: ".",
Workspace: "default",
Autoplan: valid.Autoplan{
WhenModified: []string{"**/*.tf*", "**/terragrunt.hcl"},
WhenModified: raw.DefaultAutoPlanWhenModified,
Enabled: true,
},
},
Expand All @@ -496,7 +496,7 @@ func TestProject_ToValid(t *testing.T) {
Dir: ".",
Workspace: "default",
Autoplan: valid.Autoplan{
WhenModified: []string{"**/*.tf*", "**/terragrunt.hcl"},
WhenModified: raw.DefaultAutoPlanWhenModified,
Enabled: true,
},
},
Expand All @@ -512,7 +512,7 @@ func TestProject_ToValid(t *testing.T) {
Dir: ".",
Workspace: "default",
Autoplan: valid.Autoplan{
WhenModified: []string{"**/*.tf*", "**/terragrunt.hcl"},
WhenModified: raw.DefaultAutoPlanWhenModified,
Enabled: true,
},
},
Expand Down
2 changes: 1 addition & 1 deletion server/core/config/raw/repo_cfg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ func TestConfig_ToValid(t *testing.T) {
Dir: "mydir",
Workspace: "default",
Autoplan: valid.Autoplan{
WhenModified: []string{"**/*.tf*", "**/terragrunt.hcl"},
WhenModified: raw.DefaultAutoPlanWhenModified,
Enabled: true,
},
},
Expand Down
Loading

0 comments on commit 7b7289f

Please sign in to comment.