Skip to content

Commit c39f4a7

Browse files
committed
Reproduce #5124 via integration test to validate fix
1 parent d74ca75 commit c39f4a7

File tree

7 files changed

+106
-0
lines changed

7 files changed

+106
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
variable "environment" {
2+
type = string
3+
}
4+
5+
output "environment" {
6+
value = var.environment
7+
}
8+
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Project A dpeendency on Project B using values
2+
dependency "project_b" {
3+
config_path = "../../../project-B/.terragrunt-stack/${values.env}"
4+
5+
mock_outputs = {
6+
project_b_output = "mock-project-b-output"
7+
}
8+
9+
mock_outputs_allowed_terraform_commands = ["init", "validate", "plan"]
10+
}
11+
12+
terraform {
13+
source = "."
14+
}
15+
16+
# This will fail parsing if module/ isn't excluded from discovery
17+
# because ${values} only exists in generated stack context, not during standalone parsing
18+
inputs = {
19+
environment = values.env
20+
}
21+
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# This stack references a template module that uses stack variables
2+
# The module/ directory should be excluded to avoid parsing errors
3+
4+
unit "staging" {
5+
source = "./module"
6+
path = "staging"
7+
values = {
8+
env = "staging"
9+
}
10+
}
11+
12+
unit "production" {
13+
source = "./module"
14+
path = "production"
15+
values = {
16+
env = "production"
17+
}
18+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
variable "environment" {
2+
type = string
3+
}
4+
5+
output "environment" {
6+
value = var.environment
7+
}
8+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
terraform {
2+
source = "."
3+
}
4+
5+
# This will fail parsing if module/ isn't excluded from discovery
6+
# because ${values} only exists in generated stack context, not during standalone parsing
7+
inputs = {
8+
environment = values.env
9+
}
10+
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# This stack references a template module that uses stack variables
2+
# The module/ directory should be excluded to avoid parsing errors
3+
4+
unit "staging" {
5+
source = "./module"
6+
path = "staging"
7+
values = {
8+
env = "staging"
9+
}
10+
}
11+
12+
unit "production" {
13+
source = "./module"
14+
path = "production"
15+
values = {
16+
env = "production"
17+
}
18+
}

test/integration_stacks_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ const (
4949
testFixtureReadStack = "fixtures/stacks/read-stack"
5050
testFixtureStackSelfInclude = "fixtures/stacks/self-include"
5151
testFixtureStackNestedOutputs = "fixtures/stacks/nested-outputs"
52+
testFixtureStackExcludeTemplateModule = "fixtures/stacks/exclude-template-module"
5253
testFixtureStackNoValidation = "fixtures/stacks/no-validation"
5354
testFixtureStackTerragruntDir = "fixtures/stacks/terragrunt-dir"
5455
testFixtureStacksAllNoStackDir = "fixtures/stacks/all-no-stack-dir"
@@ -126,6 +127,28 @@ func TestStacksGenerateBasicWithQueueExcludeDirFlag(t *testing.T) {
126127
validateStackDir(t, path)
127128
}
128129

130+
func TestStacksGenerateExcludeModuleWithStackVariables(t *testing.T) {
131+
t.Parallel()
132+
133+
helpers.CleanupTerraformFolder(t, testFixtureStackExcludeTemplateModule)
134+
tmpEnvPath := helpers.CopyEnvironment(t, testFixtureStackExcludeTemplateModule)
135+
rootPath := util.JoinPath(tmpEnvPath, testFixtureStackExcludeTemplateModule, "live")
136+
137+
// The module/ directory contains terragrunt.hcl that uses ${values.env} and ${values.project}
138+
// This test verifies that --queue-exclude-dir prevents parsing of template modules
139+
_, stderr, err := helpers.RunTerragruntCommandWithOutput(
140+
t,
141+
"terragrunt stack run plan --queue-exclude-dir '**/module' --working-dir "+rootPath,
142+
)
143+
require.NoError(t, err)
144+
145+
// Verify only the app unit is in the execution queue (not the module-based one)
146+
assert.Contains(t, stderr, "- Unit ./project-A/.terragrunt-stack/production")
147+
assert.Contains(t, stderr, "- Unit ./project-A/.terragrunt-stack/staging")
148+
assert.Contains(t, stderr, "- Unit ./project-B/.terragrunt-stack/production")
149+
assert.Contains(t, stderr, "- Unit ./project-B/.terragrunt-stack/staging")
150+
}
151+
129152
func TestStacksGenerateBasic(t *testing.T) {
130153
t.Parallel()
131154

0 commit comments

Comments
 (0)