Skip to content

Commit

Permalink
Fix autoplan when .terraform.lock.hcl is modifed (runatlantis#1991)
Browse files Browse the repository at this point in the history
  • Loading branch information
gezb authored and krrrr38 committed Dec 16, 2022
1 parent c211812 commit 401a26d
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 18 deletions.
2 changes: 1 addition & 1 deletion cmd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ const (
DefaultADBasicUser = ""
DefaultADBasicPassword = ""
DefaultADHostname = "dev.azure.com"
DefaultAutoplanFileList = "**/*.tf,**/*.tfvars,**/*.tfvars.json,**/terragrunt.hcl"
DefaultAutoplanFileList = "**/*.tf,**/*.tfvars,**/*.tfvars.json,**/terragrunt.hcl,**/.terraform.lock.hcl"
DefaultCheckoutStrategy = "branch"
DefaultBitbucketBaseURL = bitbucketcloud.BaseURL
DefaultDataDir = "~/.atlantis"
Expand Down
4 changes: 2 additions & 2 deletions runatlantis.io/docs/server-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ Values are chosen in this order:
* Accepts a comma separated list, ex. `pattern1,pattern2`.
* Patterns use the [`.dockerignore` syntax](https://docs.docker.com/engine/reference/builder/#dockerignore-file)
* List of file patterns will be used by both automatic and manually run plans.
* When not set, defaults to all `.tf`, `.tfvars`, `.tfvars.json` and `terragrunt.hcl` files
(`--autoplan-file-list='**/*.tf,**/*.tfvars,**/*.tfvars.json,**/terragrunt.hcl'`).
* When not set, defaults to all `.tf`, `.tfvars`, `.tfvars.json`, `terragrunt.hcl` and `.terraform.lock.hcl` files
(`--autoplan-file-list='**/*.tf,**/*.tfvars,**/*.tfvars.json,**/terragrunt.hcl,**/.terraform.lock.hcl'`).
* Setting `--autoplan-file-list` will override the defaults. You **must** add `**/*.tf` and other defaults if you want to include them.
* A custom [Workflow](repo-level-atlantis-yaml.html#configuring-planning) that uses autoplan `when_modified` will ignore this value.

Expand Down
16 changes: 15 additions & 1 deletion server/controllers/events/events_controller_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,20 @@ func TestSimlpleWorkflow_terraformLockFile(t *testing.T) {
},
LockFileTracked: false,
},
{
Description: "Modified .terraform.lock.hcl triggers autoplan ",
RepoDir: "simple-with-lockfile",
ModifiedFiles: []string{".terraform.lock.hcl"},
ExpAutoplan: true,
Comments: []string{
"atlantis plan",
},
ExpReplies: [][]string{
{"exp-output-autoplan.txt"},
{"exp-output-plan.txt"},
},
LockFileTracked: true,
},
}
for _, c := range cases {
t.Run(c.Description, func(t *testing.T) {
Expand Down Expand Up @@ -894,7 +908,7 @@ func setupE2E(t *testing.T, repoDir string) (events_controllers.VCSEventsControl
commentParser,
false,
false,
"**/*.tf,**/*.tfvars,**/*.tfvars.json,**/terragrunt.hcl",
"**/*.tf,**/*.tfvars,**/*.tfvars.json,**/terragrunt.hcl,**/.terraform.lock.hcl",
)

showStepRunner, err := runtime.NewShowStepRunner(terraformClient, defaultTFVersion)
Expand Down
6 changes: 3 additions & 3 deletions server/events/project_command_builder_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ projects:
&CommentParser{},
false,
false,
"**/*.tf,**/*.tfvars,**/*.tfvars.json,**/terragrunt.hcl",
"**/*.tf,**/*.tfvars,**/*.tfvars.json,**/terragrunt.hcl,**/.terraform.lock.hcl",
)

// We run a test for each type of command.
Expand Down Expand Up @@ -805,7 +805,7 @@ projects:
&CommentParser{},
false,
true,
"**/*.tf,**/*.tfvars,**/*.tfvars.json,**/terragrunt.hcl",
"**/*.tf,**/*.tfvars,**/*.tfvars.json,**/terragrunt.hcl,**/.terraform.lock.hcl",
)

// We run a test for each type of command, again specific projects
Expand Down Expand Up @@ -1024,7 +1024,7 @@ workflows:
&CommentParser{},
false,
false,
"**/*.tf,**/*.tfvars,**/*.tfvars.json,**/terragrunt.hcl",
"**/*.tf,**/*.tfvars,**/*.tfvars.json,**/terragrunt.hcl,**/.terraform.lock.hcl",
)

cmd := models.PolicyCheckCommand
Expand Down
20 changes: 10 additions & 10 deletions server/events/project_command_builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ projects:
&events.CommentParser{},
false,
false,
"**/*.tf,**/*.tfvars,**/*.tfvars.json,**/terragrunt.hcl",
"**/*.tf,**/*.tfvars,**/*.tfvars.json,**/terragrunt.hcl,**/.terraform.lock.hcl",
)

ctxs, err := builder.BuildAutoplanCommands(&events.CommandContext{
Expand Down Expand Up @@ -419,7 +419,7 @@ projects:
&events.CommentParser{},
false,
true,
"**/*.tf,**/*.tfvars,**/*.tfvars.json,**/terragrunt.hcl",
"**/*.tf,**/*.tfvars,**/*.tfvars.json,**/terragrunt.hcl,**/.terraform.lock.hcl",
)

var actCtxs []models.ProjectCommandContext
Expand Down Expand Up @@ -570,7 +570,7 @@ projects:
&events.CommentParser{},
false,
false,
"**/*.tf,**/*.tfvars,**/*.tfvars.json,**/terragrunt.hcl",
"**/*.tf,**/*.tfvars,**/*.tfvars.json,**/terragrunt.hcl,**/.terraform.lock.hcl",
)

ctxs, err := builder.BuildPlanCommands(
Expand Down Expand Up @@ -657,7 +657,7 @@ func TestDefaultProjectCommandBuilder_BuildMultiApply(t *testing.T) {
&events.CommentParser{},
false,
false,
"**/*.tf,**/*.tfvars,**/*.tfvars.json,**/terragrunt.hcl",
"**/*.tf,**/*.tfvars,**/*.tfvars.json,**/terragrunt.hcl,**/.terraform.lock.hcl",
)

ctxs, err := builder.BuildApplyCommands(
Expand Down Expand Up @@ -737,7 +737,7 @@ projects:
&events.CommentParser{},
false,
false,
"**/*.tf,**/*.tfvars,**/*.tfvars.json,**/terragrunt.hcl",
"**/*.tf,**/*.tfvars,**/*.tfvars.json,**/terragrunt.hcl,**/.terraform.lock.hcl",
)

ctx := &events.CommandContext{
Expand Down Expand Up @@ -812,7 +812,7 @@ func TestDefaultProjectCommandBuilder_EscapeArgs(t *testing.T) {
&events.CommentParser{},
false,
false,
"**/*.tf,**/*.tfvars,**/*.tfvars.json,**/terragrunt.hcl",
"**/*.tf,**/*.tfvars,**/*.tfvars.json,**/terragrunt.hcl,**/.terraform.lock.hcl",
)

var actCtxs []models.ProjectCommandContext
Expand Down Expand Up @@ -991,7 +991,7 @@ projects:
&events.CommentParser{},
false,
false,
"**/*.tf,**/*.tfvars,**/*.tfvars.json,**/terragrunt.hcl",
"**/*.tf,**/*.tfvars,**/*.tfvars.json,**/terragrunt.hcl,**/.terraform.lock.hcl",
)

actCtxs, err := builder.BuildPlanCommands(
Expand Down Expand Up @@ -1054,7 +1054,7 @@ projects:
&events.CommentParser{},
true,
false,
"**/*.tf,**/*.tfvars,**/*.tfvars.json,**/terragrunt.hcl",
"**/*.tf,**/*.tfvars,**/*.tfvars.json,**/terragrunt.hcl,**/.terraform.lock.hcl",
)

var actCtxs []models.ProjectCommandContext
Expand Down Expand Up @@ -1108,7 +1108,7 @@ func TestDefaultProjectCommandBuilder_WithPolicyCheckEnabled_BuildAutoplanComman
&events.CommentParser{},
false,
false,
"**/*.tf,**/*.tfvars,**/*.tfvars.json,**/terragrunt.hcl",
"**/*.tf,**/*.tfvars,**/*.tfvars.json,**/terragrunt.hcl,**/.terraform.lock.hcl",
)

ctxs, err := builder.BuildAutoplanCommands(&events.CommandContext{
Expand Down Expand Up @@ -1186,7 +1186,7 @@ func TestDefaultProjectCommandBuilder_BuildVersionCommand(t *testing.T) {
&events.CommentParser{},
false,
false,
"**/*.tf,**/*.tfvars,**/*.tfvars.json,**/terragrunt.hcl",
"**/*.tf,**/*.tfvars,**/*.tfvars.json,**/terragrunt.hcl,**/.terraform.lock.hcl",
)

ctxs, err := builder.BuildVersionCommands(
Expand Down
9 changes: 8 additions & 1 deletion server/events/project_finder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func TestDetermineProjects(t *testing.T) {
noopLogger := logging.NewNoopLogger(t)
setupTmpRepos(t)

defaultAutoplanFileList := "**/*.tf,**/*.tfvars,**/*.tfvars.json,**/terragrunt.hcl"
defaultAutoplanFileList := "**/*.tf,**/*.tfvars,**/*.tfvars.json,**/terragrunt.hcl,**/.terraform.lock.hcl"

cases := []struct {
description string
Expand Down Expand Up @@ -248,6 +248,13 @@ func TestDetermineProjects(t *testing.T) {
topLevelModules,
"**/*.yml,!project2/*.yml",
},
{
"Should not ignore .terraform.lock.hcl files",
[]string{"project1/.terraform.lock.hcl"},
[]string{"project1"},
nestedModules1,
defaultAutoplanFileList,
},
}
for _, c := range cases {
t.Run(c.description, func(t *testing.T) {
Expand Down

0 comments on commit 401a26d

Please sign in to comment.