Skip to content

HclCache in PartialParseConfigFile is never used #4522

@jkarkoszka

Description

@jkarkoszka

Describe the bug

In the PartialParseConfigFile function (located in config/config_partial.go, starting at line 282), there is a call to hclCache.Get(...). However, this cache entry is never resolved because there is no corresponding call to hclCache.Put(...) with the same cache key anywhere in the codebase.

Steps To Reproduce

  1. Create multiple terragrunt.hcl files that reference the same root-terragrunt.hcl.

  2. Run Terragrunt.

Expected behavior: root-terragrunt.hcl should be parsed only once, and subsequent accesses should hit the cache.

Actual behavior: The cache is never hit because the value is never stored -hclCache.Put(...) is missing.

func PartialParseConfigFile(ctx *ParsingContext, l log.Logger, configPath string, include *IncludeConfig) (*TerragruntConfig, error) {
	hclCache := cache.ContextCache[*hclparse.File](ctx, HclCacheContextKey)

	fileInfo, err := os.Stat(configPath)
	if err != nil {
		if os.IsNotExist(err) {
			return nil, TerragruntConfigNotFoundError{Path: configPath}
		}

		return nil, errors.New(err)
	}

	var (
		file     *hclparse.File
		cacheKey = fmt.Sprintf("configPath-%v-modTime-%v", configPath, fileInfo.ModTime().UnixMicro())
	)

	if cacheConfig, found := hclCache.Get(ctx, cacheKey); found {
		file = cacheConfig
	} else {
		file, err = hclparse.NewParser(ctx.ParserOptions...).ParseFromFile(configPath)
		if err != nil {
			return nil, err
		}
	}

	return TerragruntConfigFromPartialConfig(ctx, l, file, include)
}

Expected behavior

The cache for parsing hcl files works correctly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions