Skip to content

Commit af2f853

Browse files
committed
fix: Fixing TestDiscoveryWithSingleCustomConfigFilename
1 parent 1ea33d4 commit af2f853

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

internal/component/unit.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ type Unit struct {
2424
discoveryContext *DiscoveryContext
2525
Execution *UnitExecution
2626
path string
27+
configFile string
2728
reading []string
2829
dependencies Components
2930
dependents Components
@@ -45,6 +46,7 @@ type UnitExecution struct {
4546
func NewUnit(path string) *Unit {
4647
return &Unit{
4748
path: path,
49+
configFile: config.DefaultTerragruntConfigPath,
4850
discoveryContext: &DiscoveryContext{},
4951
dependencies: make(Components, 0),
5052
dependents: make(Components, 0),
@@ -83,6 +85,16 @@ func (u *Unit) StoreConfig(cfg *config.TerragruntConfig) {
8385
u.cfg = cfg
8486
}
8587

88+
// ConfigFile returns the discovered config filename for this unit.
89+
func (u *Unit) ConfigFile() string {
90+
return u.configFile
91+
}
92+
93+
// SetConfigFile sets the discovered config filename for this unit.
94+
func (u *Unit) SetConfigFile(filename string) {
95+
u.configFile = filename
96+
}
97+
8698
// Kind returns the kind of component (always Unit for Unit).
8799
func (u *Unit) Kind() Kind {
88100
return UnitKind

internal/discovery/discovery.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,12 @@ func Parse(
373373
case *component.Stack:
374374
configFilename = config.DefaultStackFile
375375
default:
376+
if unit, ok := c.(*component.Unit); ok && unit.ConfigFile() != "" {
377+
configFilename = unit.ConfigFile()
378+
379+
break
380+
}
381+
376382
if opts.TerragruntConfigPath != "" && !util.IsDir(opts.TerragruntConfigPath) {
377383
configFilename = filepath.Base(opts.TerragruntConfigPath)
378384
}
@@ -691,11 +697,10 @@ func (d *Discovery) processFile(
691697
// If the directory is hidden, allow it only if it matches an include pattern
692698
allowHidden := false
693699

694-
if canErr == nil {
695-
// Always allow .terragrunt-stack contents
696-
cleanDir := util.CleanPath(canonicalDir)
697-
allowHidden = isInStackDirectory(cleanDir)
698-
}
700+
// Always allow .terragrunt-stack contents. We can safely use the non-canonical
701+
// dir here because this branch is only reached when canonical path computation
702+
// failed, or when we couldn't early-return with a concrete component.
703+
allowHidden = isInStackDirectory(filepath.ToSlash(dir))
699704

700705
if !allowHidden {
701706
return nil
@@ -725,6 +730,9 @@ func (d *Discovery) createComponentFromPath(path string, filenames []string) com
725730
}
726731

727732
c := componentOfBase(dir, base)
733+
if unit, ok := c.(*component.Unit); ok {
734+
unit.SetConfigFile(base)
735+
}
728736

729737
if d.discoveryContext != nil {
730738
c.SetDiscoveryContext(d.discoveryContext)

0 commit comments

Comments
 (0)