@@ -40,15 +40,22 @@ type Runner struct {
4040}
4141
4242// buildCanonicalConfigPath computes the canonical config path for a unit.
43- // It handles .hcl/.json suffixes, joins DefaultTerragruntConfigPath when needed,
43+ // It handles .hcl/.json suffixes, joins an appropriate config filename when needed,
4444// converts to canonical absolute path, and updates the unit's path.
4545// Returns the canonical config path and the canonical unit directory.
46- func buildCanonicalConfigPath (unit * component.Unit , basePath string ) (canonicalConfigPath string , canonicalDir string , err error ) {
47- // Discovery paths are directories (e.g., "./other") not files
48- // We need to append the config filename to get the full config path
46+ func buildCanonicalConfigPath (
47+ unit * component.Unit ,
48+ basePath string ,
49+ configFileName string ,
50+ ) (canonicalConfigPath string , canonicalDir string , err error ) {
4951 terragruntConfigPath := unit .Path ()
5052 if ! strings .HasSuffix (terragruntConfigPath , ".hcl" ) && ! strings .HasSuffix (terragruntConfigPath , ".json" ) {
51- terragruntConfigPath = filepath .Join (unit .Path (), config .DefaultTerragruntConfigPath )
53+ fileName := config .DefaultTerragruntConfigPath
54+ if configFileName != "" && configFileName != "." {
55+ fileName = configFileName
56+ }
57+
58+ terragruntConfigPath = filepath .Join (unit .Path (), fileName )
5259 }
5360
5461 // Convert to canonical absolute path - this is critical for dependency resolution
@@ -152,6 +159,10 @@ func resolveUnitsFromDiscovery(
152159 }
153160
154161 basePath := stack .Path ()
162+ configFileName := config .DefaultTerragruntConfigPath
163+ if stack .Execution != nil && stack .Execution .TerragruntOptions != nil {
164+ configFileName = filepath .Base (stack .Execution .TerragruntOptions .TerragruntConfigPath )
165+ }
155166
156167 for _ , c := range discovered {
157168 unit , ok := c .(* component.Unit )
@@ -160,7 +171,7 @@ func resolveUnitsFromDiscovery(
160171 }
161172
162173 // Build canonical config path and update unit path
163- canonicalConfigPath , canonicalDir , err := buildCanonicalConfigPath (unit , basePath )
174+ canonicalConfigPath , canonicalDir , err := buildCanonicalConfigPath (unit , basePath , configFileName )
164175 if err != nil {
165176 return nil , err
166177 }
@@ -861,22 +872,22 @@ func FilterDiscoveredUnits(discovered component.Components, units []*component.U
861872
862873 // Add any missing allowed dependencies from the resolved unit graph
863874 for _ , dep := range u .Dependencies () {
864- depUnit , ok := dep .(* component.Unit )
865- if ! ok || depUnit == nil {
875+ depUnit , okDep := dep .(* component.Unit )
876+ if ! okDep || depUnit == nil {
866877 continue
867878 }
868879
869- if _ , ok := allowed [depUnit .Path ()]; ! ok {
880+ if _ , allowedOK := allowed [depUnit .Path ()]; ! allowedOK {
870881 continue
871882 }
872883
873- if _ , ok := existing [depUnit .Path ()]; ok {
884+ if _ , existsOK := existing [depUnit .Path ()]; existsOK {
874885 continue
875886 }
876887
877888 // Ensure the dependency config exists in the filtered set
878- depCfg , ok := present [depUnit .Path ()]
879- if ! ok {
889+ depCfg , presentOK := present [depUnit .Path ()]
890+ if ! presentOK {
880891 depCfg = component .NewUnit (depUnit .Path ())
881892 filtered = append (filtered , depCfg )
882893 present [depUnit .Path ()] = depCfg
0 commit comments