From 295fa93943b165db95a3fff6648d17c006ae6d55 Mon Sep 17 00:00:00 2001 From: Jesse Bye Date: Mon, 26 Aug 2019 06:06:04 -0700 Subject: [PATCH] Support terragrunt.hcl for autoplanning --- runatlantis.io/docs/custom-workflows.md | 37 +++++++++++++++++-------- server/events/project_finder.go | 4 +-- server/events/project_finder_test.go | 12 ++++++++ 3 files changed, 40 insertions(+), 13 deletions(-) diff --git a/runatlantis.io/docs/custom-workflows.md b/runatlantis.io/docs/custom-workflows.md index ce3a77bf87..1f207ab0b8 100644 --- a/runatlantis.io/docs/custom-workflows.md +++ b/runatlantis.io/docs/custom-workflows.md @@ -136,32 +136,36 @@ 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: @@ -169,8 +173,19 @@ projects: 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). diff --git a/server/events/project_finder.go b/server/events/project_finder.go index 330f2555cb..f14cb17183 100644 --- a/server/events/project_finder.go +++ b/server/events/project_finder.go @@ -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 @@ -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) } } diff --git a/server/events/project_finder_test.go b/server/events/project_finder_test.go index 53ff138da2..5a0d0304d0 100644 --- a/server/events/project_finder_test.go +++ b/server/events/project_finder_test.go @@ -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) {