Skip to content

Commit

Permalink
Ignore .tflint.hcl (#1075)
Browse files Browse the repository at this point in the history
* Ignore .tflint.hcl
  • Loading branch information
Roberto Hidalgo authored Jul 7, 2020
1 parent 42a667f commit 50a414c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 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 @@ -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 |
|---------------|---------------|----------------|----------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
Expand Down
13 changes: 7 additions & 6 deletions server/events/project_finder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}

Expand Down Expand Up @@ -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
}
Expand Down
7 changes: 7 additions & 0 deletions server/events/project_finder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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"},
Expand Down

0 comments on commit 50a414c

Please sign in to comment.