Skip to content

Commit b006906

Browse files
authored
ensure queue-include-dir includes stack paths that have not yet been generated (#4649)
* fix [#4432] [#4455]: ensure queue-include-dir includes stack paths that have not yet been generated
1 parent 4538454 commit b006906

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

test/integration_stacks_test.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,44 @@ const (
5151
testFixtureStackNoDotTerragruntStackOutput = "fixtures/stacks/no-dot-terragrunt-stack-output"
5252
)
5353

54+
func TestStacksGenerateBasicWithQueueIncludeDirFlag(t *testing.T) {
55+
t.Parallel()
56+
57+
helpers.CleanupTerraformFolder(t, testFixtureStacksBasic)
58+
tmpEnvPath := helpers.CopyEnvironment(t, testFixtureStacksBasic)
59+
rootPath := util.JoinPath(tmpEnvPath, testFixtureStacksBasic, "live")
60+
61+
_, stderr, err := helpers.RunTerragruntCommandWithOutput(t, "terragrunt run --all plan --queue-include-dir .terragrunt-stack/chicks/chick-2 --working-dir "+rootPath)
62+
require.NoError(t, err)
63+
64+
assert.NotContains(t, stderr, "- Unit ./.terragrunt-stack/chicks/chick-1")
65+
assert.NotContains(t, stderr, "- Unit ./.terragrunt-stack/father")
66+
assert.NotContains(t, stderr, "- Unit ./.terragrunt-stack/mother")
67+
assert.Contains(t, stderr, "- Unit ./.terragrunt-stack/chicks/chick-2")
68+
69+
path := util.JoinPath(rootPath, ".terragrunt-stack")
70+
validateStackDir(t, path)
71+
}
72+
73+
func TestStacksGenerateBasicWithQueueExcludeDirFlag(t *testing.T) {
74+
t.Parallel()
75+
76+
helpers.CleanupTerraformFolder(t, testFixtureStacksBasic)
77+
tmpEnvPath := helpers.CopyEnvironment(t, testFixtureStacksBasic)
78+
rootPath := util.JoinPath(tmpEnvPath, testFixtureStacksBasic, "live")
79+
80+
_, stderr, err := helpers.RunTerragruntCommandWithOutput(t, "terragrunt run --all plan --queue-exclude-dir .terragrunt-stack/chicks/chick-2 --working-dir "+rootPath)
81+
require.NoError(t, err)
82+
83+
assert.Contains(t, stderr, "- Unit ./.terragrunt-stack/chicks/chick-1")
84+
assert.Contains(t, stderr, "- Unit ./.terragrunt-stack/father")
85+
assert.Contains(t, stderr, "- Unit ./.terragrunt-stack/mother")
86+
assert.NotContains(t, stderr, "- Unit ./.terragrunt-stack/chicks/chick-2")
87+
88+
path := util.JoinPath(rootPath, ".terragrunt-stack")
89+
validateStackDir(t, path)
90+
}
91+
5492
func TestStacksGenerateBasic(t *testing.T) {
5593
t.Parallel()
5694

util/file.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,15 @@ func GlobCanonicalPath(basePath string, globPaths ...string) ([]string, error) {
117117
globPath = filepath.Join(basePath, globPath)
118118
}
119119

120+
const stackDir = "/.terragrunt-stack/"
121+
120122
matches, err := zglob.Glob(globPath)
121123
if err == nil {
122124
paths = append(paths, matches...)
125+
} else if errors.Is(err, os.ErrNotExist) && strings.Contains(CleanPath(globPath), stackDir) {
126+
// when using the stack feature, the directory may not exist yet,
127+
// as stack generation occurs after parsing the argument flags.
128+
paths = append(paths, globPath)
123129
}
124130
}
125131

0 commit comments

Comments
 (0)