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

add .hcl to supported file filter #748

Merged
merged 7 commits into from
Aug 26, 2019
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
37 changes: 26 additions & 11 deletions runatlantis.io/docs/custom-workflows.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,41 +136,56 @@ Atlantis supports running custom commands in place of the default Atlantis
commands. We can use this functionality to enable
[Terragrunt](https://github.com/gruntwork-io/terragrunt).

You can either use your repo's `atlantis.yaml` file or the Atlantis server's `repos.yaml` file.

Given a directory structure:
```
.
├── live
│   ├── prod
│   │   └── terraform.tfvars
│   └── staging
│   └── terraform.tfvars
└── modules
  └── ...
└── live
   ├── prod
   │   └── terragrunt.hcl
   └── staging
   └── terragrunt.cl
```

You would define a custom workflow:
If using the server `repos.yaml` file, you would use the following config:

```yaml
# repos.yaml or atlantis.yaml
# repos.yaml
repos:
- id: "/.*/"
workflow: terragrunt
workflows:
terragrunt:
plan:
steps:
- run: terragrunt plan -no-color -out $PLANFILE
- run: terragrunt plan -no-color -out=$PLANFILE
apply:
steps:
- run: terragrunt apply -no-color $PLANFILE
```

Which you would then reference in your repo-level `atlantis.yaml`:
If using the repo's `atlantis.yaml` file you would use the following config:
```yaml
version: 3
projects:
- dir: live/staging
workflow: terragrunt
- dir: live/prod
workflow: terragrunt
workflows:
terragrunt:
plan:
steps:
- run: terragrunt plan -no-color -out $PLANFILE
apply:
steps:
- run: terragrunt apply -no-color $PLANFILE
```

**NOTE:** If using the repo's `atlantis.yaml` file, you will need to specify each directory that is a Terragrunt project.


::: warning
Atlantis will need to have the `terragrunt` binary in its PATH.
If you're using Docker you can build your own image, see [Customization](/docs/deployment.html#customization).
Expand Down
4 changes: 2 additions & 2 deletions server/events/project_finder.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (p *DefaultProjectFinder) DetermineProjects(log *logging.SimpleLogger, modi
if len(modifiedTerraformFiles) == 0 {
return projects
}
log.Info("filtered modified files to %d .tf files: %v",
log.Info("filtered modified files to %d .tf or terragrunt.hcl files: %v",
len(modifiedTerraformFiles), modifiedTerraformFiles)

var dirs []string
Expand Down Expand Up @@ -123,7 +123,7 @@ 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") {
if !p.isStatefile(fileName) && (strings.Contains(fileName, ".tf") || filepath.Base(fileName) == "terragrunt.hcl") {
filtered = append(filtered, fileName)
}
}
Expand Down
12 changes: 12 additions & 0 deletions server/events/project_finder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,18 @@ func TestDetermineProjects(t *testing.T) {
[]string{},
"",
},
{
"Should not ignore terragrunt.hcl files",
[]string{"terragrunt.hcl"},
[]string{"."},
nestedModules2,
},
{
"Should find terragrunt.hcl file inside a nested directory",
[]string{"project1/terragrunt.hcl"},
[]string{"project1"},
nestedModules1,
},
}
for _, c := range cases {
t.Run(c.description, func(t *testing.T) {
Expand Down