$ show gruntwork-io/terragrunt
Terragrunt is a mature, production-grade Infrastructure as Code orchestration CLI tool that wraps OpenTofu and Terraform. Its core function is to manage the lifecycle of IaC modules across environments: it parses HCL configuration (`terragrunt.hcl`, stacks), discovers units and stacks in a file tree, resolves inter-module dependencies, executes OpenTofu/Terraform commands with automatic remote state backend management (S3, GCS, Azure), and caches provider downloads and module sources via a content-addressable store (CAS). The architecture is a monolith with a rich CLI surface (over 20 subcommands including `run`, `catalog`, `browse`, `scaffold`, `find`, `list`, `render`, `hcl fmt`, `dag graph`, etc.) and a custom implementation of the CLI framework (`internal/clihelper`). It features a Bubbletea-based TUI for catalog browsing and an extensible filter engine for selecting units by path, attributes, or git changes. The codebase is heavily test-covered (unit, integration, fuzz) and actively maintained by Gruntwork. Key reusable patterns include virtual abstractions for filesystem, execution, and HTTP; a generic concurrent cache; a strict controls system for deprecation gating; and a content-addressable git store for deduplicating source downloads.
The LLM identified 5 files worth highlighting for reuse:
A virtual filesystem interface (vfs.FS) that abstracts OS, in-memory, and error-injecting filesystem operations. Used throughout the codebase for all file I/O, enabling deterministic testing without real filesystem side effects. It implements walk, glob, symlink resolution, and filetype classification. This pattern is reusable for any Go project needing testable filesystem interactions.
A fully self-contained filter expression engine with lexer, parser, AST, and evaluator. Supports path globs, attribute matches, git-diff ranges, graph traversal operators (`...`, `^`), and compound expressions with `||`/`&&`. It is used by the `--filter` flag across multiple commands. This package could be extracted as a standalone library for any Go project needing a custom DSL for selecting resources.
A generic, thread-safe caching package providing `Cache` (simple map), `ExpiringCache` (TTL-based), and `RepoRootCache` with context-based lifetime. It uses hash keys for efficiency and supports telemetry counters. The package has zero external dependencies and is used by HCL parsing, config resolution, and runner pools. It is reusable in any Go application needing a lightweight in-memory cache with customizable eviction.
A virtual environment abstraction (`venv.Venv`) that bundles filesystem, execution, HTTP client, SOPS decrypter, environment, and writer interfaces into a single struct. This allows entire subsystems (getters, runners, config parsing) to be tested with purely in-memory mock backends. It replaces global state and enables clean dependency injection. The pattern is reusable for any Go project seeking test isolation of subprocess and filesystem operations.
A custom CLI framework built on top of urfave/cli that adds reusable flag types (SliceFlag, MapFlag, GenericFlag), env var binding with automatic pass-through, deprecation/strict-control integration, exit code routing, and help template generation. It standardizes how all Terragrunt commands handle flags, arguments, and errors. This package is reusable as a lightweight extension to urfave/cli for any Go CLI application.