From 5e855875b01f9abdf94d8d47f712f0ced30d8e6e Mon Sep 17 00:00:00 2001 From: Roberto Hidalgo Date: Wed, 3 Jun 2020 20:40:09 -0400 Subject: [PATCH 1/4] Ignore .tflint.hcl Fixes #1061 --- runatlantis.io/docs/repo-level-atlantis-yaml.md | 2 +- server/events/project_finder.go | 8 ++++---- server/events/project_finder_test.go | 7 +++++++ 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/runatlantis.io/docs/repo-level-atlantis-yaml.md b/runatlantis.io/docs/repo-level-atlantis-yaml.md index 3dbd3593c8..6c3ad7b44d 100644 --- a/runatlantis.io/docs/repo-level-atlantis-yaml.md +++ b/runatlantis.io/docs/repo-level-atlantis-yaml.md @@ -229,7 +229,7 @@ Atlantis supports this but requires the `name` key to be specified. See [Custom ### Autoplan ```yaml enabled: true -when_modified: ["*.tf"] +when_modified: ["*.tf", "terragrunt.hcl"] ``` | Key | Type | Default | Required | Description | |---------------|---------------|----------------|----------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| diff --git a/server/events/project_finder.go b/server/events/project_finder.go index b0db61718a..f4c54fe31f 100644 --- a/server/events/project_finder.go +++ b/server/events/project_finder.go @@ -136,16 +136,16 @@ func (p *DefaultProjectFinder) filterToTerraform(files []string) []string { for _, fileName := range files { // Filter out tfstate files since they usually checked in by accident // and regardless, they don't affect a plan. - if !p.isStatefile(fileName) && (strings.Contains(fileName, ".tf") || filepath.Base(fileName) == "terragrunt.hcl") { + if !p.shouldIgnore(fileName) && (strings.Contains(fileName, ".tf") || filepath.Base(fileName) == "terragrunt.hcl") { filtered = append(filtered, fileName) } } return filtered } -// isStatefile returns true if fileName is a terraform statefile or backup. -func (p *DefaultProjectFinder) isStatefile(fileName string) bool { - for _, s := range []string{"terraform.tfstate", "terraform.tfstate.backup"} { +// shouldIgnore returns true if fileName is a terraform statefile, backup or tflint file. +func (p *DefaultProjectFinder) shouldIgnore(fileName string) bool { + for _, s := range []string{"terraform.tfstate", "terraform.tfstate.backup", "tflint.hcl"} { if strings.Contains(fileName, s) { return true } diff --git a/server/events/project_finder_test.go b/server/events/project_finder_test.go index 5b10325e45..31e1b1ec74 100644 --- a/server/events/project_finder_test.go +++ b/server/events/project_finder_test.go @@ -53,6 +53,7 @@ func setupTmpRepos(t *testing.T) { Ok(t, err) files := []string{ "non-tf", + ".tflint.hcl", "terraform.tfstate.backup", "project1/main.tf", "project1/terraform.tfstate", @@ -123,6 +124,12 @@ func TestDetermineProjects(t *testing.T) { nil, nestedModules1, }, + { + "Should ignore .tflint.hcl files and return an empty list", + []string{".tflint.hcl", "project1/.tflint.hcl"}, + nil, + nestedModules1, + }, { "Should plan in the parent directory from modules if that dir has a main.tf", []string{"project1/modules/main.tf"}, From 4fa093c06b8722d9aab454cbf67a8e1f57037dfb Mon Sep 17 00:00:00 2001 From: Roberto Hidalgo Date: Wed, 3 Jun 2020 20:48:56 -0400 Subject: [PATCH 2/4] Turn ignored file list into a fixed lenght list and export it --- server/events/project_finder.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/server/events/project_finder.go b/server/events/project_finder.go index f4c54fe31f..05970197ad 100644 --- a/server/events/project_finder.go +++ b/server/events/project_finder.go @@ -40,6 +40,9 @@ type ProjectFinder interface { DetermineProjectsViaConfig(log *logging.SimpleLogger, modifiedFiles []string, config valid.RepoCfg, absRepoDir string) ([]valid.Project, error) } +// IgnoredFiles contains filename fragments to ignore while looking at changes +var IgnoredFiles = [...]string{"terraform.tfstate", "terraform.tfstate.backup", "tflint.hcl"} + // DefaultProjectFinder implements ProjectFinder. type DefaultProjectFinder struct{} @@ -145,7 +148,7 @@ func (p *DefaultProjectFinder) filterToTerraform(files []string) []string { // shouldIgnore returns true if fileName is a terraform statefile, backup or tflint file. func (p *DefaultProjectFinder) shouldIgnore(fileName string) bool { - for _, s := range []string{"terraform.tfstate", "terraform.tfstate.backup", "tflint.hcl"} { + for _, s := range IgnoredFiles { if strings.Contains(fileName, s) { return true } From 52b30b40988be2a4a5a30243bedf32c33aede533 Mon Sep 17 00:00:00 2001 From: Roberto Hidalgo Date: Tue, 7 Jul 2020 13:45:45 -0400 Subject: [PATCH 3/4] follow feedback --- server/events/project_finder.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/server/events/project_finder.go b/server/events/project_finder.go index 05970197ad..9e738cbe42 100644 --- a/server/events/project_finder.go +++ b/server/events/project_finder.go @@ -40,8 +40,8 @@ type ProjectFinder interface { DetermineProjectsViaConfig(log *logging.SimpleLogger, modifiedFiles []string, config valid.RepoCfg, absRepoDir string) ([]valid.Project, error) } -// IgnoredFiles contains filename fragments to ignore while looking at changes -var IgnoredFiles = [...]string{"terraform.tfstate", "terraform.tfstate.backup", "tflint.hcl"} +// ignoredFilenameFragments contains filename fragments to ignore while looking at changes +var ignoredFilenameFragments = string{"terraform.tfstate", "terraform.tfstate.backup", "tflint.hcl"} // DefaultProjectFinder implements ProjectFinder. type DefaultProjectFinder struct{} @@ -137,8 +137,6 @@ func (p *DefaultProjectFinder) DetermineProjectsViaConfig(log *logging.SimpleLog func (p *DefaultProjectFinder) filterToTerraform(files []string) []string { var filtered []string for _, fileName := range files { - // Filter out tfstate files since they usually checked in by accident - // and regardless, they don't affect a plan. if !p.shouldIgnore(fileName) && (strings.Contains(fileName, ".tf") || filepath.Base(fileName) == "terragrunt.hcl") { filtered = append(filtered, fileName) } @@ -146,7 +144,7 @@ func (p *DefaultProjectFinder) filterToTerraform(files []string) []string { return filtered } -// shouldIgnore returns true if fileName is a terraform statefile, backup or tflint file. +// shouldIgnore returns true if we shouldn't trigger a plan on changes to this file. func (p *DefaultProjectFinder) shouldIgnore(fileName string) bool { for _, s := range IgnoredFiles { if strings.Contains(fileName, s) { From 9c09a141390c87a5e6b4e7d1806c0d186e9183d0 Mon Sep 17 00:00:00 2001 From: Roberto Hidalgo Date: Tue, 7 Jul 2020 14:00:35 -0400 Subject: [PATCH 4/4] =?UTF-8?q?=F0=9F=A4=A6=F0=9F=8F=BD=E2=80=8D=E2=99=82?= =?UTF-8?q?=EF=B8=8F=20pay=20attention=20and=20jump=20less=20guns?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/events/project_finder.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/events/project_finder.go b/server/events/project_finder.go index 9e738cbe42..6c68a1fd61 100644 --- a/server/events/project_finder.go +++ b/server/events/project_finder.go @@ -41,7 +41,7 @@ type ProjectFinder interface { } // ignoredFilenameFragments contains filename fragments to ignore while looking at changes -var ignoredFilenameFragments = string{"terraform.tfstate", "terraform.tfstate.backup", "tflint.hcl"} +var ignoredFilenameFragments = []string{"terraform.tfstate", "terraform.tfstate.backup", "tflint.hcl"} // DefaultProjectFinder implements ProjectFinder. type DefaultProjectFinder struct{} @@ -146,7 +146,7 @@ func (p *DefaultProjectFinder) filterToTerraform(files []string) []string { // shouldIgnore returns true if we shouldn't trigger a plan on changes to this file. func (p *DefaultProjectFinder) shouldIgnore(fileName string) bool { - for _, s := range IgnoredFiles { + for _, s := range ignoredFilenameFragments { if strings.Contains(fileName, s) { return true }