gruntwork-io / terragrunt

Terragrunt is a flexible orchestration tool that allows Infrastructure as Code written in OpenTofu/Terraform to scale.
https://terragrunt.gruntwork.io/
MIT License
7.91k stars 966 forks source link

Reduce Reliance on Global Cache #3198

Closed yhakbar closed 4 weeks ago

yhakbar commented 2 months ago

We rely on global variables for shared cache state, which is an anti-pattern we should refactor out of the codebase.

This can cause issues with integration testing, and can increase the memory footprint of Terragrunt.

Develop a new mechanism for explicitly passing around that cache through a cache manager so that we can be more thoughtful with how we're caching content throughout an invocation of Terragrunt. Refactor caching throughout the codebase to leverage it.

yhakbar commented 2 months ago

An interesting observation made was that we generally are looking for caching to support memoization of our function calls.

Leveraging a OnceFunc with something to old the functions for re-use might provide a good pattern for a large scale refactor.

yhakbar commented 4 weeks ago

@denis256 did some refactoring within https://github.com/gruntwork-io/terragrunt/pull/3307 to pass in cache by context instead of a global cache, so we can consider this work done.

In the future, we may want to revisit this and refactor further to avoid storing the cache in the ctx parameter, etc.