From 50a414cc2dabe5b844d6124d663d37fab0ce10ab Mon Sep 17 00:00:00 2001 From: Roberto Hidalgo Date: Tue, 7 Jul 2020 14:06:52 -0400 Subject: [PATCH] Ignore .tflint.hcl (#1075) * Ignore .tflint.hcl --- runatlantis.io/docs/repo-level-atlantis-yaml.md | 2 +- server/events/project_finder.go | 13 +++++++------ server/events/project_finder_test.go | 7 +++++++ 3 files changed, 15 insertions(+), 7 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..6c68a1fd61 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) } +// 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{} @@ -134,18 +137,16 @@ 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.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 we shouldn't trigger a plan on changes to this file. +func (p *DefaultProjectFinder) shouldIgnore(fileName string) bool { + for _, s := range ignoredFilenameFragments { 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"},