@@ -50,6 +50,7 @@ const (
5050 testFixtureStackTerragruntDir = "fixtures/stacks/terragrunt-dir"
5151 testFixtureStacksAllNoStackDir = "fixtures/stacks/all-no-stack-dir"
5252 testFixtureStackNoDotTerragruntStackOutput = "fixtures/stacks/no-dot-terragrunt-stack-output"
53+ testFixtureStackFindInParentFolders = "fixtures/stacks/find-in-parent-folders"
5354)
5455
5556func TestStacksGenerateBasicWithQueueIncludeDirFlag (t * testing.T ) {
@@ -1393,3 +1394,47 @@ func TestStackOutputWithNoDotTerragruntStack(t *testing.T) {
13931394
13941395 assert .Contains (t , stdout , "name = \" app1\" " )
13951396}
1397+
1398+ func TestStackFindInParentFolders (t * testing.T ) {
1399+ t .Parallel ()
1400+
1401+ helpers .CleanupTerraformFolder (t , testFixtureStackFindInParentFolders )
1402+ tmpEnvPath := helpers .CopyEnvironment (t , testFixtureStackFindInParentFolders )
1403+ rootPath := util .JoinPath (tmpEnvPath , testFixtureStackFindInParentFolders , "live" )
1404+
1405+ // Test that stack generation works from the live directory
1406+ helpers .RunTerragrunt (t , "terragrunt stack generate --working-dir " + rootPath )
1407+
1408+ // Verify that the stack directory was created and contains the expected unit
1409+ stackDir := util .JoinPath (rootPath , "stack" , ".terragrunt-stack" )
1410+ validateStackDir (t , stackDir )
1411+
1412+ // Verify that the foo unit was generated
1413+ fooUnitPath := util .JoinPath (stackDir , "foo" )
1414+ assert .True (t , util .FileExists (fooUnitPath ), "Expected foo unit to exist in .terragrunt-stack directory" )
1415+ assert .True (t , util .FileExists (util .JoinPath (fooUnitPath , "terragrunt.hcl" )), "Expected terragrunt.hcl to exist in foo unit" )
1416+
1417+ // Test that stack generation works from the parent directory (this tests our fix)
1418+ parentPath := util .JoinPath (tmpEnvPath , testFixtureStackFindInParentFolders )
1419+ helpers .RunTerragrunt (t , "terragrunt stack generate --working-dir " + parentPath )
1420+
1421+ // Verify that the stack directory was created from the parent directory
1422+ parentStackDir := util .JoinPath (parentPath , "live" , "stack" , ".terragrunt-stack" )
1423+ validateStackDir (t , parentStackDir )
1424+
1425+ // Verify that the foo unit was generated from the parent directory
1426+ parentFooUnitPath := util .JoinPath (parentStackDir , "foo" )
1427+ assert .True (t , util .FileExists (parentFooUnitPath ), "Expected foo unit to exist when generating from parent directory" )
1428+ assert .True (t , util .FileExists (util .JoinPath (parentFooUnitPath , "terragrunt.hcl" )), "Expected terragrunt.hcl to exist in foo unit when generating from parent directory" )
1429+
1430+ stackPath := util .JoinPath (rootPath , "stack" )
1431+
1432+ _ , _ , err := helpers .RunTerragruntCommandWithOutput (t , "terragrunt stack run apply --non-interactive --working-dir " + stackPath )
1433+ require .NoError (t , err , "Expected stack run apply to succeed" )
1434+
1435+ outputStdout , _ , err := helpers .RunTerragruntCommandWithOutput (t , "terragrunt stack output --raw foo.mock --non-interactive --working-dir " + stackPath )
1436+ require .NoError (t , err , "Expected stack output to succeed" )
1437+
1438+ // Verify that the mock value from mock.hcl was correctly passed through
1439+ assert .Equal (t , "mock" , strings .TrimSpace (outputStdout ), "Expected raw output to contain just the mock value" )
1440+ }
0 commit comments