Skip to content
Open
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 Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION=1.16.0
VERSION=1.17.0
PATH_BUILD=build/
FILE_COMMAND=terragrunt-atlantis-config
FILE_ARCH=darwin_amd64
Expand Down
23 changes: 12 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,14 @@ If you specify `extra_atlantis_dependencies` in the parent Terragrunt module, th
One way to customize the behavior of this module is through CLI flag values passed in at runtime. These settings will apply to all modules.

| Flag Name | Description | Default Value |
|------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------|
| ---------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------- |
| `--autoplan` | The default value for autoplan settings. Can be overriden by locals. | false |
| `--automerge` | Enables the automerge setting for a repo. | false |
| `--cascade-dependencies` | When true, dependencies will cascade, meaning that a module will be declared to depend not only on its dependencies, but all dependencies of its dependencies all the way down. | true |
| `--ignore-parent-terragrunt` | Ignore parent Terragrunt configs (those which don't reference a terraform module).<br>In most cases, this should be set to `true` | true |
| `--parallel` | Enables `plan`s and `apply`s to happen in parallel. Will typically be used with `--create-workspace` | true |
| `--create-workspace` | Use different auto-generated workspace for each project. Default is use default workspace for everything | false |
| `--create-project-name` | Add different auto-generated name for each project | false |
| `--create-project-name` | Add different auto-generated name for each project. The project names can be customised thanks to the local variable `atlantis_project_name`, see [All Locals](#all-locals). | false |
| `--preserve-workflows` | Preserves workflows from old output files. Useful if you want to define your workflow definitions on the client side | true |
| `--preserve-projects` | Preserves projects from old output files. Useful for incremental builds using `--filter` | false |
| `--workflow` | Name of the workflow to be customized in the atlantis server. If empty, will be left out of output | "" |
Expand All @@ -137,26 +137,27 @@ One way to customize the behavior of this module is through CLI flag values pass

These flags offer additional options to generate Atlantis projects based on HCL configuration files in the terragrunt hierarchy. This, for example, enables Atlantis to use `terragrunt run-all` workflows on staging environment or product levels in a terragrunt hierarchy. Mostly useful in large terragrunt projects containing lots of interdependent child modules. Atlantis `locals` can be used in the defined project marker files.

| Flag Name | Description | Default Value | Type |
| ---------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------- |----- |
| `--project-hcl-files` | Comma-separated names of arbitrary hcl files in the terragrunt hierarchy to create Atlantis projects for.<br>Disables the `--filter` flag | "" | list(string) |
| `--use-project-markers` | If enabled, project hcl files must include `locals { atlantis_project = true }` for project creation. | false | bool |
| `--create-hcl-project-childs` | Creates Atlantis projects for terragrunt child modules below the directories containing the HCL files defined in --project-hcl-files | false | bool |
| `--create-hcl-project-external-childs` | Creates Atlantis projects for terragrunt child modules outside the directories containing the HCL files defined in --project-hcl-files | true | bool |
| Flag Name | Description | Default Value | Type |
| -------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------- | ------------- | ------------ |
| `--project-hcl-files` | Comma-separated names of arbitrary hcl files in the terragrunt hierarchy to create Atlantis projects for.<br>Disables the `--filter` flag | "" | list(string) |
| `--use-project-markers` | If enabled, project hcl files must include `locals { atlantis_project = true }` for project creation. | false | bool |
| `--create-hcl-project-childs` | Creates Atlantis projects for terragrunt child modules below the directories containing the HCL files defined in --project-hcl-files | false | bool |
| `--create-hcl-project-external-childs` | Creates Atlantis projects for terragrunt child modules outside the directories containing the HCL files defined in --project-hcl-files | true | bool |

## All Locals

Another way to customize the output is to use `locals` values in your terragrunt modules. These can be set in either the parent or child terragrunt modules, and the settings will only affect the current module (or all child modules for parent locals).

| Locals Name | Description | type |
| ----------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------ |
| `atlantis_workflow` | The custom atlantis workflow name to use for a module | string |
| `atlantis_apply_requirements` | The custom `apply_requirements` array to use for a module | list(string) |
| `atlantis_terraform_version` | Allows overriding the `--terraform-version` flag for a single module | string |
| `atlantis_autoplan` | Allows overriding the `--autoplan` flag for a single module | bool |
| `atlantis_project_name` | The custom atlantis project name to use for a module, jointly with the `--create-project-name` flag | string |
| `atlantis_project` | Create Atlantis project for a project hcl file. Only functional with `--project-hcl-files` and `--use-project-markers` | bool |
| `atlantis_skip` | If true on a child module, that module will not appear in the output.<br>If true on a parent module, none of that parent's children will appear in the output. | bool |
| `atlantis_terraform_version` | Allows overriding the `--terraform-version` flag for a single module | string |
| `atlantis_workflow` | The custom atlantis workflow name to use for a module | string |
| `extra_atlantis_dependencies` | See [Extra dependencies](https://github.com/transcend-io/terragrunt-atlantis-config#extra-dependencies) | list(string) |
| `atlantis_project` | Create Atlantis project for a project hcl file. Only functional with `--project-hcl-files` and `--use-project-markers` | bool |

## Separate workspace for parallel plan and apply

Expand Down
6 changes: 6 additions & 0 deletions cmd/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,9 @@ func createProject(sourcePath string) (*AtlantisProject, error) {
// We are going to use the same name for both workspace & project name as it is unique.
regex := regexp.MustCompile(`[^a-zA-Z0-9_-]+`)
projectName := regex.ReplaceAllString(project.Dir, "_")
if locals.AtlantisProjectName != "" {
projectName = locals.AtlantisProjectName
}

if createProjectName {
project.Name = projectName
Expand Down Expand Up @@ -563,6 +566,9 @@ func createHclProject(sourcePaths []string, workingDir string, projectHcl string
// We are going to use the same name for both workspace & project name as it is unique.
regex := regexp.MustCompile(`[^a-zA-Z0-9_-]+`)
projectName := regex.ReplaceAllString(project.Dir, "_")
if locals.AtlantisProjectName != "" {
projectName = locals.AtlantisProjectName
}

if createProjectName {
project.Name = projectName
Expand Down
9 changes: 9 additions & 0 deletions cmd/generate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ func runTest(t *testing.T, goldenFile string, args []string) {
}, args...)

contentBytes, err := RunWithFlags(filename, allArgs)

content := &AtlantisConfig{}
yaml.Unmarshal(contentBytes, content)
if err != nil {
Expand Down Expand Up @@ -235,6 +236,14 @@ func TestWithProjectNames(t *testing.T) {
})
}

func TestCustomProjectName(t *testing.T) {
runTest(t, filepath.Join("golden", "custom_project_name.yaml"), []string{
"--root",
filepath.Join("..", "test_examples", "custom_project_name"),
"--create-project-name",
})
}

func TestMergingLocalDependenciesFromParent(t *testing.T) {
runTest(t, filepath.Join("golden", "mergeParentDependencies.yaml"), []string{
"--root",
Expand Down
12 changes: 12 additions & 0 deletions cmd/golden/custom_project_name.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
automerge: false
parallel_apply: true
parallel_plan: true
projects:
- autoplan:
enabled: false
when_modified:
- '*.hcl'
- '*.tf*'
dir: projectA
name: project-a
version: 3
6 changes: 6 additions & 0 deletions cmd/golden/envhcl_allchilds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,12 @@ projects:
- ../terragrunt.hcl
dir: child_and_parent_specify_workflow/child
workflow: workflowSpecifiedInChild
- autoplan:
enabled: false
when_modified:
- '*.hcl'
- '*.tf*'
dir: custom_project_name/projectA
- autoplan:
enabled: false
when_modified:
Expand Down
6 changes: 6 additions & 0 deletions cmd/golden/envhcl_externalchilds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,12 @@ projects:
- ../terragrunt.hcl
dir: child_and_parent_specify_workflow/child
workflow: workflowSpecifiedInChild
- autoplan:
enabled: false
when_modified:
- '*.hcl'
- '*.tf*'
dir: custom_project_name/projectA
- autoplan:
enabled: false
when_modified:
Expand Down
12 changes: 12 additions & 0 deletions cmd/parse_locals.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ type ResolvedLocals struct {
// The Atlantis workflow to use for some project
AtlantisWorkflow string

// The Atlantis project name to use for some project
AtlantisProjectName string

// Apply requirements to override the global `--apply-requirements` flag
ApplyRequirements []string

Expand Down Expand Up @@ -73,6 +76,10 @@ func mergeResolvedLocals(parent ResolvedLocals, child ResolvedLocals) ResolvedLo
parent.AtlantisWorkflow = child.AtlantisWorkflow
}

if child.AtlantisProjectName != "" {
parent.AtlantisProjectName = child.AtlantisProjectName
}

if child.TerraformVersion != "" {
parent.TerraformVersion = child.TerraformVersion
}
Expand Down Expand Up @@ -145,6 +152,11 @@ func resolveLocals(localsAsCty cty.Value) ResolvedLocals {
resolved.AtlantisWorkflow = workflowValue.AsString()
}

projectNameValue, ok := rawLocals["atlantis_project_name"]
if ok {
resolved.AtlantisProjectName = projectNameValue.AsString()
}

versionValue, ok := rawLocals["atlantis_terraform_version"]
if ok {
resolved.TerraformVersion = versionValue.AsString()
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ require (
github.com/imdario/mergo v0.3.12 // indirect
github.com/mattn/go-zglob v0.0.2 // indirect
github.com/sirupsen/logrus v1.6.0
github.com/spf13/cobra v0.0.5
github.com/spf13/cobra v1.6.0
github.com/stretchr/testify v1.7.0
github.com/urfave/cli v1.22.4 // indirect
github.com/zclconf/go-cty v1.8.3
Expand Down
16 changes: 10 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,9 @@ github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfc
github.com/cpuguy83/go-md2man v1.0.10 h1:BSKMNlYxDvnunlTymqtgONjNnaRV1sTpcovwwjF22jk=
github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/cpuguy83/go-md2man/v2 v2.0.0 h1:EoUDS0afbrsXAZ9YQ9jdu/mZ2sXgT1/2yyNng4PGlyM=
github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w=
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/creack/pty v1.1.11 h1:07n33Z8lZxZ2qwegKbObQohDhXDQxiMMz1NOUGYlesw=
Expand Down Expand Up @@ -599,8 +600,9 @@ github.com/imdario/mergo v0.3.7/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJ
github.com/imdario/mergo v0.3.11/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA=
github.com/imdario/mergo v0.3.12 h1:b6R2BslTbIEToALKP7LxUvijTsNI9TAe80pLWN2g/HU=
github.com/imdario/mergo v0.3.12/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA=
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/inconshreveable/mousetrap v1.0.1 h1:U3uMjPSQEBMNp1lFxmllqCPM6P5u/Xq7Pgzkat/bFNc=
github.com/inconshreveable/mousetrap v1.0.1/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/jhump/protoreflect v1.6.0/go.mod h1:eaTn3RZAmMBcV0fifFvlm6VHNz3wSkYyXYWUh7ymB74=
github.com/jinzhu/copier v0.0.0-20190924061706-b57f9002281a/go.mod h1:yL958EeXv8Ylng6IfnvG4oflryUi3vgA3xPs9hmII1s=
github.com/jmespath/go-jmespath v0.0.0-20160202185014-0b12d6b521d8/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
Expand Down Expand Up @@ -811,8 +813,9 @@ github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFR
github.com/rubiojr/go-vhd v0.0.0-20160810183302-0bfd3b39853c/go.mod h1:DM5xW0nvfNNm2uytzsvhI3OnX8uzaRAg8UX/CnDqbto=
github.com/russross/blackfriday v1.5.2 h1:HyvC0ARfnZBqnXwABFeSZHpKvJHJJfPz81GNueLj0oo=
github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g=
github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q=
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/ryanuber/columnize v2.1.0+incompatible/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
github.com/ryanuber/go-glob v1.0.0 h1:iQh3xXAumdQ+4Ufa5b25cRpC5TYKlno6hsv6Cb3pkBk=
github.com/ryanuber/go-glob v1.0.0/go.mod h1:807d1WSdnB0XRJzKNil9Om6lcp/3a0v4qIHxIXzX/Yc=
Expand All @@ -822,7 +825,6 @@ github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo=
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
github.com/sirupsen/logrus v1.0.4-0.20170822132746-89742aefa4b2/go.mod h1:pMByvHTf9Beacp5x1UXfOR9xyW/9antXMhjMPG0dEzc=
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
Expand All @@ -843,8 +845,9 @@ github.com/spf13/afero v1.2.2/go.mod h1:9ZxEEn6pIJ8Rxe320qSDBk6AsU0r9pR7Q4OcevTd
github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
github.com/spf13/cobra v0.0.2-0.20171109065643-2da4a54c5cee/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ=
github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ=
github.com/spf13/cobra v0.0.5 h1:f0B+LkLX6DtmRH1isoNA9VTtNUK9K8xYd28JNNfOv/s=
github.com/spf13/cobra v0.0.5/go.mod h1:3K3wKZymM7VvHMDS9+Akkh4K60UwM26emMESw8tLCHU=
github.com/spf13/cobra v1.6.0 h1:42a0n6jwCot1pUmomAp4T7DeMD+20LFv4Q54pxLf2LI=
github.com/spf13/cobra v1.6.0/go.mod h1:IOw/AERYS7UzyrGinqmz6HLUo219MORXGxhbaJUqzrY=
github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo=
github.com/spf13/pflag v0.0.0-20170130214245-9ff6c6923cff/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/spf13/pflag v1.0.1-0.20171106142849-4c012f6dcd95/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
Expand Down Expand Up @@ -1434,8 +1437,9 @@ gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU=
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20210107172259-749611fa9fcc h1:XANm4xAMEQhRdWKqaL0qmhGDv7RuobwCO97TIlktaQE=
gopkg.in/yaml.v3 v3.0.0-20210107172259-749611fa9fcc/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw=
gotest.tools/v3 v3.0.2/go.mod h1:3SzNCllyD9/Y+b5r9JIKQ474KzkZyqLqEfYqMsX94Bk=
honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import "github.com/transcend-io/terragrunt-atlantis-config/cmd"
// This variable is set at build time using -ldflags parameters.
// But we still set a default here for those using plain `go get` downloads
// For more info, see: http://stackoverflow.com/a/11355611/483528
var VERSION string = "1.16.0"
var VERSION string = "1.17.0"

func main() {
cmd.Execute(VERSION)
Expand Down
11 changes: 11 additions & 0 deletions test_examples/custom_project_name/projectA/terragrunt.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
terraform {
source = "git::[email protected]:transcend-io/terraform-aws-fargate-container?ref=v0.0.4"
}

locals {
atlantis_project_name = "project-a"
}

inputs = {
foo = "bar"
}
7 changes: 4 additions & 3 deletions test_examples/with_parent/child/terragrunt.hcl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
include {
path = find_in_parent_folders()
include "root" {
path = find_in_parent_folders()
expose = true
}

terraform {
Expand All @@ -8,4 +9,4 @@ terraform {

inputs = {
foo = "bar"
}
}