Skip to content

Commit

Permalink
Support terragrunt.hcl for autoplanning
Browse files Browse the repository at this point in the history
  • Loading branch information
Jesse Bye authored and lkysow committed Aug 26, 2019
1 parent 4b8f3e4 commit 295fa93
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 13 deletions.
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

0 comments on commit 295fa93

Please sign in to comment.