Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore .tflint.hcl #1075

Merged
merged 4 commits into from
Jul 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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