Skip to content

Commit

Permalink
Make dependsOnList unique, duplicates when extra arguments are added
Browse files Browse the repository at this point in the history
  • Loading branch information
trahim committed Dec 26, 2024
1 parent 8d12b66 commit 3846bf8
Show file tree
Hide file tree
Showing 11 changed files with 101 additions and 6 deletions.
8 changes: 5 additions & 3 deletions cmd/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import (
"golang.org/x/sync/semaphore"
"golang.org/x/sync/singleflight"

"bitbucket.org/creachadair/stringset"

"context"
"os"
"path/filepath"
Expand Down Expand Up @@ -830,7 +832,7 @@ func main(cmd *cobra.Command, args []string) error {
hasChanges = false
for _, project := range config.Projects {
executionOrderGroup := 0
dependsOnList := []string{}
dependsOnList := stringset.New()
// choose order group based on dependencies
for _, dep := range project.Autoplan.WhenModified {
depPath := filepath.ToSlash(filepath.Dir(filepath.Join(project.Dir, dep)))
Expand All @@ -849,14 +851,14 @@ func main(cmd *cobra.Command, args []string) error {
executionOrderGroup = *depProject.ExecutionOrderGroup + 1
}
}
dependsOnList = append(dependsOnList, depProject.Name)
dependsOnList.Add(depProject.Name)
}
if projectsMap[project.Dir].ExecutionOrderGroup == nil || *projectsMap[project.Dir].ExecutionOrderGroup != executionOrderGroup {
if executionOrderGroups {
projectsMap[project.Dir].ExecutionOrderGroup = &executionOrderGroup
}
if dependsOn {
projectsMap[project.Dir].DependsOn = dependsOnList
projectsMap[project.Dir].DependsOn = dependsOnList.Elements()
}
// repeat the main cycle when changed some project
hasChanges = true
Expand Down
10 changes: 10 additions & 0 deletions cmd/generate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,16 @@ func TestIgnoringTerragruntDependencies(t *testing.T) {
})
}

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


func TestCustomWorkflowName(t *testing.T) {
runTest(t, filepath.Join("golden", "different_workflow_names.yaml"), []string{
"--root",
Expand Down
15 changes: 15 additions & 0 deletions cmd/golden/envhcl_allchilds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -784,6 +784,21 @@ projects:
- '*.tf*'
- ../dependency/terragrunt.hcl
dir: terragrunt_dependency/depender
- autoplan:
enabled: false
when_modified:
- '*.hcl'
- '*.tf*'
- extra.tfvars
dir: terragrunt_dependency_extra_arguments/dependency
- autoplan:
enabled: false
when_modified:
- '*.hcl'
- '*.tf*'
- ../dependency/terragrunt.hcl
- ../dependency/extra.tfvars
dir: terragrunt_dependency_extra_arguments/depender
- autoplan:
enabled: false
when_modified:
Expand Down
15 changes: 15 additions & 0 deletions cmd/golden/envhcl_externalchilds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,21 @@ projects:
- '*.tf*'
- ../dependency/terragrunt.hcl
dir: terragrunt_dependency/depender
- autoplan:
enabled: false
when_modified:
- '*.hcl'
- '*.tf*'
- extra.tfvars
dir: terragrunt_dependency_extra_arguments/dependency
- autoplan:
enabled: false
when_modified:
- '*.hcl'
- '*.tf*'
- ../dependency/terragrunt.hcl
- ../dependency/extra.tfvars
dir: terragrunt_dependency_extra_arguments/depender
- autoplan:
enabled: false
when_modified:
Expand Down
24 changes: 24 additions & 0 deletions cmd/golden/terragrunt_dependency_extra_arguments.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
automerge: false
parallel_apply: true
parallel_plan: true
projects:
- autoplan:
enabled: false
when_modified:
- '*.hcl'
- '*.tf*'
- extra.tfvars
dir: dependency
name: dependency
- autoplan:
enabled: false
when_modified:
- '*.hcl'
- '*.tf*'
- ../dependency/terragrunt.hcl
- ../dependency/extra.tfvars
depends_on:
- dependency
dir: depender
name: depender
version: 3
2 changes: 1 addition & 1 deletion cmd/golden/withDependsOn.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ projects:
- ../dependency/terragrunt.hcl
- nested/terragrunt.hcl
depends_on:
- depender
- dependency
- depender
- depender_on_depender_nested
dir: depender_on_depender
name: depender_on_depender
Expand Down
2 changes: 1 addition & 1 deletion cmd/golden/withExecutionOrderGroupsAndDependsOn.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ projects:
- ../dependency/terragrunt.hcl
- nested/terragrunt.hcl
depends_on:
- depender
- dependency
- depender
- depender_on_depender_nested
dir: depender_on_depender
execution_order_group: 2
Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ require (
)

require (
bitbucket.org/creachadair/stringset v0.0.14 // indirect
cloud.google.com/go v0.110.10 // indirect
cloud.google.com/go/compute v1.23.1 // indirect
cloud.google.com/go/compute/metadata v0.2.3 // indirect
Expand Down Expand Up @@ -123,7 +124,7 @@ require (
go.uber.org/atomic v1.9.0 // indirect
golang.org/x/crypto v0.14.0 // indirect
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
golang.org/x/mod v0.12.0 // indirect
golang.org/x/mod v0.15.0 // indirect
golang.org/x/net v0.17.0 // indirect
golang.org/x/oauth2 v0.13.0 // indirect
golang.org/x/sys v0.20.0 // indirect
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
bitbucket.org/creachadair/stringset v0.0.14 h1:t1ejQyf8utS4GZV/4fM+1gvYucggZkfhb+tMobDxYOE=
bitbucket.org/creachadair/stringset v0.0.14/go.mod h1:Ej8fsr6rQvmeMDf6CCWMWGb14H9mz8kmDgPPTdiVT0w=
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSRU=
Expand Down Expand Up @@ -1050,6 +1052,8 @@ golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/mod v0.12.0 h1:rmsUpXtvNzj340zd98LZ4KntptpfRHwpFOHG188oHXc=
golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/mod v0.15.0 h1:SernR4v+D55NyBH2QiEQrlBAnj1ECL6AGrA5+dPaMY8=
golang.org/x/mod v0.15.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/net v0.0.0-20170114055629-f2499483f923/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180530234432-1e491301e022/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
terraform {
source = "git::[email protected]:transcend-io/terraform-aws-fargate-container?ref=v0.0.4"
extra_arguments "extra" {
commands = get_terraform_commands_that_need_vars()
optional_var_files = [
"${get_terragrunt_dir()}/extra.tfvars",
]
}
}

inputs = {
foo = "bar"
}
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"
}

dependency "some_dep" {
config_path = "../dependency"
}

inputs = {
foo = dependency.some_dep.outputs.some_output
}

0 comments on commit 3846bf8

Please sign in to comment.