Skip to content

Commit

Permalink
Support incremental builds (#207)
Browse files Browse the repository at this point in the history
  • Loading branch information
dmattia authored Feb 26, 2022
1 parent 0cafe04 commit db0e063
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION=1.12.5
VERSION=1.13.0
PATH_BUILD=build/
FILE_COMMAND=terragrunt-atlantis-config
FILE_ARCH=darwin_amd64
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Then, make sure `terragrunt-atlantis-config` is present on your Atlantis server.

```hcl
variable "terragrunt_atlantis_config_version" {
default = "1.12.5"
default = "1.13.0"
}
build {
Expand Down Expand Up @@ -122,6 +122,7 @@ One way to customize the behavior of this module is through CLI flag values pass
| `--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 |
| `--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 | "" |
| `--apply-requirements` | Requirements that must be satisfied before `atlantis apply` can be run. Currently the only supported requirements are `approved` and `mergeable`. Can be overridden by locals | [] |
| `--output` | Path of the file where configuration will be generated. Typically, you want a file named "atlantis.yaml". Default is to write to `stdout`. | "" |
Expand Down Expand Up @@ -189,7 +190,7 @@ You can install this tool locally to checkout what kinds of config it will gener
Recommended: Install any version via go get:

```bash
cd && GO111MODULE=on go get github.com/transcend-io/terragrunt-atlantis-config@v1.12.5 && cd -
cd && GO111MODULE=on go get github.com/transcend-io/terragrunt-atlantis-config@v1.13.0 && cd -
```

This module officially supports golang versions v1.13, v1.14, v1.15, and v1.16, tested on CircleCI with each build
Expand Down
3 changes: 3 additions & 0 deletions cmd/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,9 @@ func main(cmd *cobra.Command, args []string) error {
if oldConfig != nil && preserveWorkflows {
config.Workflows = oldConfig.Workflows
}
if oldConfig != nil && preserveProjects {
config.Projects = oldConfig.Projects
}

lock := sync.Mutex{}
ctx := context.Background()
Expand Down
48 changes: 48 additions & 0 deletions cmd/generate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ func resetForRun() error {
createWorkspace = false
createProjectName = false
preserveWorkflows = true
preserveProjects = true
defaultWorkflow = ""
filterPath = ""
outputPath = ""
Expand Down Expand Up @@ -355,6 +356,53 @@ func TestPreservingOldWorkflows(t *testing.T) {
}
}

func TestPreservingOldProjects(t *testing.T) {
err := resetForRun()
if err != nil {
t.Error("Failed to reset default flags")
return
}

randomInt := rand.Int()
filename := filepath.Join("test_artifacts", fmt.Sprintf("%d.yaml", randomInt))
defer os.Remove(filename)

// Create an existing file to simulate an existing atlantis.yaml file
contents := []byte(`projects:
- autoplan:
enabled: false
when_modified:
- '*.hcl'
- '*.tf*'
dir: someDir
name: projectFromPreviousRun
`)
ioutil.WriteFile(filename, contents, 0644)

content, err := RunWithFlags(filename, []string{
"generate",
"--preserve-projects",
"--output",
filename,
"--root",
filepath.Join("..", "test_examples", "basic_module"),
})
if err != nil {
t.Error("Failed to read file")
return
}

goldenContents, err := ioutil.ReadFile(filepath.Join("golden", "oldProjectsPreserved.yaml"))
if err != nil {
t.Error("Failed to read golden file")
return
}

if string(content) != string(goldenContents) {
t.Errorf("Content did not match golden file.\n\nExpected Content: %s\n\nContent: %s", string(goldenContents), string(content))
}
}

func TestEnablingAutomerge(t *testing.T) {
runTest(t, filepath.Join("golden", "withAutomerge.yaml"), []string{
"--root",
Expand Down
18 changes: 18 additions & 0 deletions cmd/golden/oldProjectsPreserved.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
automerge: false
parallel_apply: true
parallel_plan: true
projects:
- autoplan:
enabled: false
when_modified:
- '*.hcl'
- '*.tf*'
dir: .
- autoplan:
enabled: false
when_modified:
- '*.hcl'
- '*.tf*'
dir: someDir
name: projectFromPreviousRun
version: 3
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.12.5"
var VERSION string = "1.13.0"

func main() {
cmd.Execute(VERSION)
Expand Down

0 comments on commit db0e063

Please sign in to comment.