feat: add --terragrunt-no-cache parameter for run_cmd#4951
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
📝 WalkthroughWalkthroughAdds a new --terragrunt-no-cache run_cmd flag that disables cache lookup and storage, implements conflict detection with --terragrunt-global-cache (new ConflictingRunCmdCacheOptionsError), updates tests and fixtures (quiet/global-cache/no-cache), expands run_cmd docs, and promotes github.com/mattn/go-shellwords to a direct dependency. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor User
participant TG as Terragrunt.RunCommand
participant Cache as CacheStore
participant Shell as Shell
User->>TG: run_cmd(args, flags)
alt flags include --terragrunt-no-cache
TG->>Shell: execute command (no cache path)
Shell-->>TG: stdout/stderr
Note right of TG #f0f4c3: Skip cache read/write
else default / maybe --terragrunt-global-cache
TG->>Cache: lookup(key, scope)
alt cache hit
Cache-->>TG: cached result
else cache miss
TG->>Shell: execute command
Shell-->>TG: stdout/stderr
TG->>Cache: store(key, scope, result)
end
end
opt --terragrunt-quiet
Note over TG #e3f2fd: Suppress / redact sensitive output
end
TG-->>User: result or error
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~30 minutes Possibly related PRs
Suggested reviewers
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
--terragrunt-no-cache parameter for run_cmd
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (5)
test/fixtures/run-cmd-flags/scripts/emit_secret.sh (1)
5-5: Prefer printf for deterministic output (avoid trailing newline).Use printf to avoid newline-sensitive parsing issues in tests/pipelines.
-echo "TOP_SECRET_TOKEN" +printf "%s" "TOP_SECRET_TOKEN"go.mod (1)
95-95: Direct dep on go-shellwords looks fine; verify duplication with google/shlex.Both github.com/mattn/go-shellwords and github.com/google/shlex are present. Consider standardizing on one to avoid divergent parsing behaviors. Run go mod tidy to ensure indirects are trimmed.
test/fixtures/run-cmd-flags/module-quiet/main.tf (1)
5-7: Mark secret output as sensitive to avoid leaking.Set sensitive = true to prevent accidental exposure in CLI/logs.
output "quiet_secret" { value = var.secret + sensitive = true }test/fixtures/run-cmd-flags/scripts/global_counter.sh (1)
8-18: Potential race on counter file under parallel runs.Concurrent executions could clobber writes. For robustness, lock the file (flock) or write to a temp file and mv atomically. Also consider printf for deterministic output formatting.
test/fixtures/run-cmd-flags/scripts/no_cache_counter.sh (1)
8-18: Same file write race risk as global_counter.sh.Use flock or temp+mv to avoid lost updates if executed in parallel. printf can provide consistent output formatting.
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (16)
config/config_helpers.go(4 hunks)config/config_helpers_test.go(1 hunks)docs-starlight/src/content/docs/04-reference/01-hcl/04-functions.mdx(3 hunks)go.mod(1 hunks)test/fixtures/run-cmd-flags/module-global-cache-a/main.tf(1 hunks)test/fixtures/run-cmd-flags/module-global-cache-a/terragrunt.hcl(1 hunks)test/fixtures/run-cmd-flags/module-global-cache-b/main.tf(1 hunks)test/fixtures/run-cmd-flags/module-global-cache-b/terragrunt.hcl(1 hunks)test/fixtures/run-cmd-flags/module-no-cache/main.tf(1 hunks)test/fixtures/run-cmd-flags/module-no-cache/terragrunt.hcl(1 hunks)test/fixtures/run-cmd-flags/module-quiet/main.tf(1 hunks)test/fixtures/run-cmd-flags/module-quiet/terragrunt.hcl(1 hunks)test/fixtures/run-cmd-flags/scripts/emit_secret.sh(1 hunks)test/fixtures/run-cmd-flags/scripts/global_counter.sh(1 hunks)test/fixtures/run-cmd-flags/scripts/no_cache_counter.sh(1 hunks)test/integration_run_cmd_flags_test.go(1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.go
⚙️ CodeRabbit configuration file
Review the Go code for quality and correctness. Make sure that the Go code follows best practices, is performant, and is easy to understand and maintain.
Files:
config/config_helpers_test.goconfig/config_helpers.gotest/integration_run_cmd_flags_test.go
docs-starlight/**/*.md*
⚙️ CodeRabbit configuration file
Review the documentation for clarity, grammar, and spelling. Make sure that the documentation is easy to understand and follow. There is currently a migration underway from the Jekyll based documentation in
docsto the Starlight + Astro based documentation indocs-starlight. Make sure that thedocs-starlightdocumentation is accurate and up-to-date with thedocsdocumentation, and that any difference between them results in an improvement in thedocs-starlightdocumentation.
Files:
docs-starlight/src/content/docs/04-reference/01-hcl/04-functions.mdx
🧬 Code graph analysis (1)
test/integration_run_cmd_flags_test.go (2)
test/helpers/package.go (3)
CleanupTerraformFolder(878-885)CopyEnvironment(88-101)RunTerragruntCommandWithOutput(993-997)util/file.go (1)
JoinPath(626-628)
🪛 LanguageTool
docs-starlight/src/content/docs/04-reference/01-hcl/04-functions.mdx
[grammar] ~723-~723: There might be a mistake here.
Context: ... | | --terragrunt-global-cache | Stores a...
(QB_NEW_EN)
[style] ~814-~814: This adverb was used twice in the sentence. Consider removing one of them or replacing them with a synonym.
Context: ...appears only once since it's declared only ininputs`, which is evaluated once T...
(ADVERB_REPETITION_PREMIUM)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
- GitHub Check: base_tests / Test (macos)
- GitHub Check: base_tests / Test (ubuntu)
- GitHub Check: Pull Request has non-contributor approval
🔇 Additional comments (16)
test/fixtures/run-cmd-flags/module-global-cache-b/terragrunt.hcl (1)
1-8: LGTM: correct use of --terragrunt-global-cache.Locals/inputs wired properly.
test/fixtures/run-cmd-flags/module-quiet/terragrunt.hcl (1)
1-8: LGTM: quiet run_cmd wiring is correct.Inputs reference local.secret as expected.
test/fixtures/run-cmd-flags/module-global-cache-a/main.tf (1)
1-7: LGTM: module interface is correct.Variable and output are consistent with fixture usage.
test/fixtures/run-cmd-flags/module-no-cache/main.tf (1)
1-15: LGTM!Test fixture is correctly structured to support the no-cache testing scenario.
test/fixtures/run-cmd-flags/module-no-cache/terragrunt.hcl (1)
1-10: LGTM!The fixture correctly exercises the
--terragrunt-no-cacheflag by calling the same script twice, which will verify that caching is properly disabled.test/fixtures/run-cmd-flags/module-global-cache-b/main.tf (1)
1-7: LGTM!Test fixture is correctly structured to support global cache testing across multiple modules.
config/config_helpers_test.go (1)
200-219: Excellent test coverage for the new flag.The test cases comprehensively cover
--terragrunt-no-cachein various combinations with other flags. The test on Line 217 combines all three flags (including the contradictory--terragrunt-global-cacheand--terragrunt-no-cache), which is good for documenting precedence behavior where--terragrunt-no-cachetakes precedence and disables all caching.config/config_helpers.go (3)
348-370: LGTM!The
disableCacheflag implementation is clean and follows the established pattern for other--terragrunt-*flags. The flag is correctly processed before the command execution.
377-388: LGTM!Cache lookup is correctly skipped when
--terragrunt-no-cacheis set. The updated comments clearly document this behavior.
403-408: LGTM!Cache storage is correctly skipped when
--terragrunt-no-cacheis set, maintaining consistency with the cache lookup behavior.test/fixtures/run-cmd-flags/module-global-cache-a/terragrunt.hcl (1)
1-8: LGTM!Fixture correctly demonstrates
--terragrunt-global-cacheusage for sharing cached values across modules.test/integration_run_cmd_flags_test.go (3)
16-32: LGTM!Constants and types are well-organized with clear, descriptive names.
34-59: LGTM!The helper function is well-structured with proper cleanup and environment setup. Capturing both stdout and stderr enables comprehensive output verification.
61-93: LGTM!Integration tests effectively verify the three key behaviors:
--terragrunt-quietproperly redacts sensitive output--terragrunt-global-cacheshares results across modules--terragrunt-no-cachebypasses caching entirelyThe tests include both positive assertions (expected values present) and negative assertions (unexpected values absent).
docs-starlight/src/content/docs/04-reference/01-hcl/04-functions.mdx (2)
701-726: LGTM!The new "Basic Usage" and "Special Parameters" sections significantly improve the documentation. The table format clearly explains each flag's purpose with concrete examples.
767-816: LGTM!The "Caching Behavior" section provides an excellent explanation of how
run_cmdcaching works by default. The example with detailed output and key observations helps users understand the caching mechanics, particularly how different arguments create different cache keys.
docs-starlight/src/content/docs/04-reference/01-hcl/04-functions.mdx
Outdated
Show resolved
Hide resolved
docs-starlight/src/content/docs/04-reference/01-hcl/04-functions.mdx
Outdated
Show resolved
Hide resolved
docs-starlight/src/content/docs/04-reference/01-hcl/04-functions.mdx
Outdated
Show resolved
Hide resolved
docs-starlight/src/content/docs/04-reference/01-hcl/04-functions.mdx
Outdated
Show resolved
Hide resolved
yhakbar
left a comment
There was a problem hiding this comment.
Let's make it an error to use both global cache and no cache at the same time.
|
Great work, btw! |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
docs-starlight/src/content/docs/04-reference/01-hcl/04-functions.mdx (2)
750-756: Solid examples for no‑cache; minor style tweak optional.Looks good. Optional: drop “on” to read “Gets the current timestamp each parse…”.
-# Gets current timestamp on each parse of the Terragrunt configuration +# Gets the current timestamp each parse of the Terragrunt configuration
727-729: Fix comma splice and keep style crisp.-Terragrunt caches `run_cmd` results by default to avoid running the same command multiple times during parsing. The cache key includes the directory of the `terragrunt.hcl` file and the command arguments unless you opt into global caching or disable caching entirely. -Parameters `--terragrunt-global-cache` and `--terragrunt-no-cache` are mutually exclusive, Terragrunt will return an error if both are provided. +Terragrunt caches `run_cmd` results by default to avoid running the same command multiple times during parsing. The cache key includes the directory of the `terragrunt.hcl` file and the command arguments, unless you opt into global caching or disable caching entirely. +Parameters `--terragrunt-global-cache` and `--terragrunt-no-cache` are mutually exclusive. Terragrunt returns an error if both are provided.
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (7)
config/config_helpers.go(4 hunks)config/config_helpers_test.go(1 hunks)config/errors.go(1 hunks)docs-starlight/src/content/docs/04-reference/01-hcl/04-functions.mdx(3 hunks)test/fixtures/run-cmd-flags/module-conflict/main.tf(1 hunks)test/fixtures/run-cmd-flags/module-conflict/terragrunt.hcl(1 hunks)test/integration_run_cmd_flags_test.go(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
- config/config_helpers_test.go
- config/config_helpers.go
🧰 Additional context used
📓 Path-based instructions (2)
**/*.go
⚙️ CodeRabbit configuration file
Review the Go code for quality and correctness. Make sure that the Go code follows best practices, is performant, and is easy to understand and maintain.
Files:
test/integration_run_cmd_flags_test.goconfig/errors.go
docs-starlight/**/*.md*
⚙️ CodeRabbit configuration file
Review the documentation for clarity, grammar, and spelling. Make sure that the documentation is easy to understand and follow. There is currently a migration underway from the Jekyll based documentation in
docsto the Starlight + Astro based documentation indocs-starlight. Make sure that thedocs-starlightdocumentation is accurate and up-to-date with thedocsdocumentation, and that any difference between them results in an improvement in thedocs-starlightdocumentation.
Files:
docs-starlight/src/content/docs/04-reference/01-hcl/04-functions.mdx
🧬 Code graph analysis (1)
test/integration_run_cmd_flags_test.go (2)
test/helpers/package.go (3)
CleanupTerraformFolder(878-885)CopyEnvironment(88-101)RunTerragruntCommandWithOutput(993-997)util/file.go (1)
JoinPath(626-628)
🪛 LanguageTool
docs-starlight/src/content/docs/04-reference/01-hcl/04-functions.mdx
[grammar] ~723-~723: There might be a mistake here.
Context: ... | | --terragrunt-global-cache | Stores a...
(QB_NEW_EN)
[style] ~811-~811: This adverb was used twice in the sentence. Consider removing one of them or replacing them with a synonym.
Context: ...appears only once since it's declared only ininputs`, which is evaluated once T...
(ADVERB_REPETITION_PREMIUM)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
- GitHub Check: codespell / Check Spelling
- GitHub Check: Pull Request has non-contributor approval
- GitHub Check: build-and-test
🔇 Additional comments (14)
config/errors.go (1)
149-153: LGTM!The new error type follows the established pattern of other error types in this file. The error message is clear, actionable, and correctly describes the conflicting options scenario.
test/fixtures/run-cmd-flags/module-conflict/terragrunt.hcl (1)
1-8: LGTM!This test fixture correctly demonstrates the conflicting cache options scenario. The intentional use of both
--terragrunt-global-cacheand--terragrunt-no-cacheon Line 3 is designed to trigger theConflictingRunCmdCacheOptionsErrorfor testing purposes.test/fixtures/run-cmd-flags/module-conflict/main.tf (1)
1-7: LGTM!This minimal Terraform module is appropriately scoped for the conflict testing scenario. The pass-through variable and output structure aligns with the integration test requirements.
test/integration_run_cmd_flags_test.go (6)
1-27: LGTM!The package structure, imports, and constants are well-organized. The test fixture paths and expected values are clearly named and appropriately scoped.
29-65: LGTM!The
runCmdFlagsFixturehelper function is well-structured and properly usest.Helper(). The removal of the conflict module on Lines 52-53 is correctly documented and necessary to allow happy-path tests to runterragrunt run --allwithout errors.
67-74: LGTM!The test correctly verifies that the
--terragrunt-quietflag redacts sensitive output while confirming the secret value is not leaked in stderr.
76-90: LGTM!The test effectively validates global cache behavior by checking both the counter file (ensuring single execution) and the output contents (verifying cached result reuse across modules).
92-99: LGTM!The test properly verifies that
--terragrunt-no-cachebypasses the cache and produces fresh output rather than reusing cached results.
101-114: LGTM!The test correctly validates the conflicting cache options scenario. It properly:
- Sets up its own isolated environment (including the conflict module that was removed in the helper)
- Expects an error when both
--terragrunt-global-cacheand--terragrunt-no-cacheare used together- Verifies the error message in stderr, which is appropriate for an integration test
docs-starlight/src/content/docs/04-reference/01-hcl/04-functions.mdx (5)
701-701: Good addition: clear section header.“Basic Usage” improves scannability. No issues.
741-747: Example reads well and matches semantics.Clear illustration of directory‑independent caching. LGTM.
758-763: Nice combined‑flags example.Shows quiet + no‑cache without confusion. Good.
764-766: Helpful sectioning.“Caching Behavior” intro is clear and accurate.
719-726: Tighten phrasing and clarify global-cache scopeTwo minor wording tweaks—streamline the intro and make it explicit that the global cache is per Terragrunt run. Consider also adding “within a single Terragrunt invocation” to the Caching Behavior section for consistency.
The `run_cmd` function accepts some special flags that can alter how the function evaluates commands on your behalf. Placing these `--terragrunt-` prefixed flags as the first argument(s) of a `run_cmd` call will result in the behavior of `run_cmd` being adjusted. You can mix and match the flags in any order, so long as they precede the command you are running with `run_cmd`. --- The `run_cmd` function accepts special flags that alter how it evaluates commands. Place `--terragrunt-` flags as the first argument(s) to adjust `run_cmd` behavior. Flags can be combined in any order, as long as they precede the command.| `--terragrunt-global-cache` | Stores and reuses results in a global cache so the command only runs once per set of arguments, no matter which configuration references it. Useful when the output is directory-independent. | … --- | `--terragrunt-global-cache` | Stores and reuses results in a global cache so the command runs only once per unique set of arguments—regardless of which configuration references it—within a single Terragrunt run. Useful when the output is directory-independent. | …
docs-starlight/src/content/docs/04-reference/01-hcl/04-functions.mdx
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
docs-starlight/src/content/docs/04-reference/01-hcl/04-functions.mdx (1)
728-729: Fix comma splice in mutual exclusivity sentenceSplit the sentence or use a semicolon so the guidance reads cleanly.
-Parameters `--terragrunt-global-cache` and `--terragrunt-no-cache` are mutually exclusive, Terragrunt will return an error if both are provided. +Parameters `--terragrunt-global-cache` and `--terragrunt-no-cache` are mutually exclusive; Terragrunt returns an error if both are provided.
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
docs-starlight/src/content/docs/04-reference/01-hcl/04-functions.mdx(3 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
docs-starlight/**/*.md*
⚙️ CodeRabbit configuration file
Review the documentation for clarity, grammar, and spelling. Make sure that the documentation is easy to understand and follow. There is currently a migration underway from the Jekyll based documentation in
docsto the Starlight + Astro based documentation indocs-starlight. Make sure that thedocs-starlightdocumentation is accurate and up-to-date with thedocsdocumentation, and that any difference between them results in an improvement in thedocs-starlightdocumentation.
Files:
docs-starlight/src/content/docs/04-reference/01-hcl/04-functions.mdx
🪛 LanguageTool
docs-starlight/src/content/docs/04-reference/01-hcl/04-functions.mdx
[grammar] ~723-~723: There might be a mistake here.
Context: ... | | --terragrunt-global-cache | Stores a...
(QB_NEW_EN)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
- GitHub Check: license_check / License Check
- GitHub Check: lint / lint
- GitHub Check: build-and-test
- GitHub Check: Pull Request has non-contributor approval
Description
--terragrunt-no-cacheparameter fornrun_cmdrun_cmdrun_cmdparametersTODOs
Read the Gruntwork contribution guidelines.
Release Notes (draft)
Added / Removed / Updated [X].
Migration Guide
Summary by CodeRabbit
New Features
Documentation
Tests