Repository navigation
fix(list): never read remote Terraform state when listing inventory - #2820
thejrose1984 wants to merge 17 commits into
Conversation
|
Tip Atmos Pro
No affected stacks workflow was detected for this pull request. |
|
💥 This pull request now has conflicts. Could you fix it thejrose1984? 🙏 |
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughAdds warn-mode recovery for wrapped Terraform state-read failures, preserves strict and fatal error behavior, adds contextual ChangesTerraform state recovery and diagnostics
Estimated code review effort: 3 (Moderate) | ~25 minutes Possibly related PRs
Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 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 |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@cmd/list/inventory_credentialed_functions_test.go`:
- Around line 157-163: Update the inline comments in the argument list near
newAuthenticatedManager to end each comment with a period, including
“ignoreMissingFiles,” “processTemplates,” “processYamlFunctions,”
“includeEmptyStacks,” “skip,” and “authDisabled.”
- Around line 222-246: Update TestSkipCredentialBackedYAMLFunctionsForInventory
to define the complete expected bare-token credential-backed function list
directly in the test, independent of credentialBackedYAMLFunctions(). Compare
that expected set against both credentialBackedYAMLFunctions() and
skipCredentialBackedYAMLFunctions(nil), while retaining the existing
caller-entry preservation and non-mutation assertions.
In `@internal/exec/describe_stacks_yaml_function_hints.go`:
- Around line 16-23: Update resolvesTerraformStateFunctions in
internal/exec/describe_stacks_yaml_function_hints.go:16-23 to return false only
when both normalized Terraform function names are present in p.skip, while
retaining true for either individual skip. In
internal/exec/describe_stacks_yaml_function_hints_test.go:61-75, add
table-driven cases covering each individual skip entry and assert hints remain
attached.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 8479b73b-043d-406e-b518-aaa69c51b11d
📒 Files selected for processing (15)
cmd/list/components.gocmd/list/dependencies.gocmd/list/instances.gocmd/list/inventory_credentialed_functions_test.gocmd/list/stacks.gocmd/list/utils.godocs/fixes/2026-07-28-inventory-commands-read-remote-tfstate.mdinternal/exec/describe_stacks_component_processor.gointernal/exec/describe_stacks_yaml_function_hints.gointernal/exec/describe_stacks_yaml_function_hints_test.gowebsite/docs/cli/commands/describe/describe-stacks.mdxwebsite/docs/cli/commands/list/list-components.mdxwebsite/docs/cli/commands/list/list-dependencies.mdxwebsite/docs/cli/commands/list/list-instances.mdxwebsite/docs/cli/commands/list/list-stacks.mdx
|
Because list output is customizable and can include these values we cannot disable it entirely. Instead we should continue investing to ensure values are not eagerly resolved. |
48f814c to
63fc41f
Compare
Addresses review feedback on cloudposse#2820. The previous revision skipped credential-backed YAML functions unconditionally for inventory commands. That was too blunt: list output is customizable and can legitimately render these values, so resolution must be demand-driven rather than disabled. `skipCredentialBackedYAMLFunctionsForInventory` now takes an `outputCanSurfaceValues` flag and returns the caller's `--skip` untouched when true. Each command answers from what it was actually asked to render: - `list stacks` / `list components`: custom `--columns` or a `list.*.columns` block in atmos.yaml - `list dependencies`: never — it renders a fixed graph of component/stack names - `list instances`: `--columns`, `--query`, `--filter`, or `--upload` The test is conservative: any customization counts, because Atmos cannot know whether `{{ .vars.x }}` came from a YAML function without resolving it first. Only the built-in default columns, which render identity fields Atmos derives itself, are provably value-free. That fixes the reported command (plain `atmos list stacks`) while leaving customized output working as before. Also from review: - Fix `resolvesTerraformStateFunctions`, which suppressed the describe-stacks hints when *either* terraform function was skipped. A partial skip still resolves the other against a remote backend, so the guidance must survive; only skipping both is credential-free. Table-driven test added. - Replace the tautological skip-set assertion with an independent expected list, so removing a function from the helper now fails the test. - Terminate inline comments with periods (godot) and document the remaining test helpers. Adds `TestExecuteAndExtractStacks_ResolvesWhenColumnsAreCustomized` as the negative path, so a regression back to an unconditional skip fails the build. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01UtnSvasDtm8t3pWAdvX9ex
|
Thanks — fair call, and you're right that the first pass was too blunt. A custom Pushed a rework: resolution is demand-driven now rather than disabled.
The test is deliberately conservative: any customization counts, since we can't know To be clear on scope: this is demand at the command level, not the lazy resolution One open question — the Linked Issues check flags that #2566 also names |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
cmd/list/inventory_credentialed_functions_test.go (1)
231-297: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winConsider a fixture-driven regression test for
list instancestoo.Stacks and components get full cross-account fixture integration tests (identity success + customized-columns negative path).
list instancesonly gets the predicate-levelTestInstancesOutputCanSurfaceValues, even though it has the largest surface for surfacing values (--query,--filter,--upload). Extending the same fixture pattern to instances would close the loop the same way it did for stacks/components.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@cmd/list/inventory_credentialed_functions_test.go` around lines 231 - 297, Add fixture-driven integration coverage for list instances, matching the existing cross-account tests for stacks and components: verify the identity-success path and a negative path where custom value-surfacing options cause credential-backed functions to be evaluated and the unreachable fixture expression fails. Exercise the instances-specific options identified by instancesOutputCanSurfaceValues, including query, filter, or upload, while preserving the existing predicate-level test.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@cmd/list/inventory_credentialed_functions_test.go`:
- Around line 231-297: Add fixture-driven integration coverage for list
instances, matching the existing cross-account tests for stacks and components:
verify the identity-success path and a negative path where custom
value-surfacing options cause credential-backed functions to be evaluated and
the unreachable fixture expression fails. Exercise the instances-specific
options identified by instancesOutputCanSurfaceValues, including query, filter,
or upload, while preserving the existing predicate-level test.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: ac81854e-2d09-4b8b-8d7c-13bd1f8c13c7
📒 Files selected for processing (13)
cmd/list/components.gocmd/list/dependencies.gocmd/list/instances.gocmd/list/inventory_credentialed_functions_test.gocmd/list/stacks.gocmd/list/utils.godocs/fixes/2026-07-28-inventory-commands-read-remote-tfstate.mdinternal/exec/describe_stacks_yaml_function_hints.gointernal/exec/describe_stacks_yaml_function_hints_test.gowebsite/docs/cli/commands/list/list-components.mdxwebsite/docs/cli/commands/list/list-dependencies.mdxwebsite/docs/cli/commands/list/list-instances.mdxwebsite/docs/cli/commands/list/list-stacks.mdx
🚧 Files skipped from review as they are similar to previous changes (9)
- website/docs/cli/commands/list/list-dependencies.mdx
- cmd/list/dependencies.go
- website/docs/cli/commands/list/list-stacks.mdx
- cmd/list/instances.go
- website/docs/cli/commands/list/list-components.mdx
- cmd/list/stacks.go
- website/docs/cli/commands/list/list-instances.mdx
- internal/exec/describe_stacks_yaml_function_hints.go
- cmd/list/components.go
Addresses the remaining CodeRabbit nitpick on cloudposse#2820: stacks and components each had full cross-account fixture coverage (authenticated success plus a customized-output negative path) while `list instances` only had the predicate-level test, despite having the largest value-surfacing surface (--query, --filter, --upload). The new tests drive the real executeListInstancesCmd by swapping the listAuthManagerFactory seam cloudposse#2801 introduced, so they exercise the production skip wiring rather than re-deriving it in the test. The negative path is table-driven over --query, --filter and --columns. Both instances and stacks negative paths now assert errors.Is(err, ErrDescribeComponent) rather than merely requiring an error. Confirmed that is the real cause, so a malformed query or column template can no longer satisfy the test while proving nothing about resolution. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01UtnSvasDtm8t3pWAdvX9ex
Addresses review feedback on cloudposse#2820. The previous revision skipped credential-backed YAML functions unconditionally for inventory commands. That was too blunt: list output is customizable and can legitimately render these values, so resolution must be demand-driven rather than disabled. `skipCredentialBackedYAMLFunctionsForInventory` now takes an `outputCanSurfaceValues` flag and returns the caller's `--skip` untouched when true. Each command answers from what it was actually asked to render: - `list stacks` / `list components`: custom `--columns` or a `list.*.columns` block in atmos.yaml - `list dependencies`: never — it renders a fixed graph of component/stack names - `list instances`: `--columns`, `--query`, `--filter`, or `--upload` The test is conservative: any customization counts, because Atmos cannot know whether `{{ .vars.x }}` came from a YAML function without resolving it first. Only the built-in default columns, which render identity fields Atmos derives itself, are provably value-free. That fixes the reported command (plain `atmos list stacks`) while leaving customized output working as before. Also from review: - Fix `resolvesTerraformStateFunctions`, which suppressed the describe-stacks hints when *either* terraform function was skipped. A partial skip still resolves the other against a remote backend, so the guidance must survive; only skipping both is credential-free. Table-driven test added. - Replace the tautological skip-set assertion with an independent expected list, so removing a function from the helper now fails the test. - Terminate inline comments with periods (godot) and document the remaining test helpers. Adds `TestExecuteAndExtractStacks_ResolvesWhenColumnsAreCustomized` as the negative path, so a regression back to an unconditional skip fails the build. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01UtnSvasDtm8t3pWAdvX9ex
75188ce to
acec1ab
Compare
Addresses the remaining CodeRabbit nitpick on cloudposse#2820: stacks and components each had full cross-account fixture coverage (authenticated success plus a customized-output negative path) while `list instances` only had the predicate-level test, despite having the largest value-surfacing surface (--query, --filter, --upload). The new tests drive the real executeListInstancesCmd by swapping the listAuthManagerFactory seam cloudposse#2801 introduced, so they exercise the production skip wiring rather than re-deriving it in the test. The negative path is table-driven over --query, --filter and --columns. Both instances and stacks negative paths now assert errors.Is(err, ErrDescribeComponent) rather than merely requiring an error. Confirmed that is the real cause, so a malformed query or column template can no longer satisfy the test while proving nothing about resolution. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01UtnSvasDtm8t3pWAdvX9ex
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@website/docs/cli/commands/describe/describe-stacks.mdx`:
- Around line 31-34: Qualify the documentation so credential-free behavior
applies only to the default inventory output: update
website/docs/cli/commands/describe/describe-stacks.mdx lines 31-34 to state that
default identity-only columns avoid remote-state resolution, while customized
columns may still resolve credential-backed values; update
docs/fixes/2026-07-28-inventory-commands-read-remote-tfstate.md lines 50-52 to
describe the helper as serving default inventory output.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: ace70c8a-a70d-4877-9106-d6ce9dcdc3ed
📒 Files selected for processing (15)
cmd/list/components.gocmd/list/dependencies.gocmd/list/instances.gocmd/list/inventory_credentialed_functions_test.gocmd/list/stacks.gocmd/list/utils.godocs/fixes/2026-07-28-inventory-commands-read-remote-tfstate.mdinternal/exec/describe_stacks_component_processor.gointernal/exec/describe_stacks_yaml_function_hints.gointernal/exec/describe_stacks_yaml_function_hints_test.gowebsite/docs/cli/commands/describe/describe-stacks.mdxwebsite/docs/cli/commands/list/list-components.mdxwebsite/docs/cli/commands/list/list-dependencies.mdxwebsite/docs/cli/commands/list/list-instances.mdxwebsite/docs/cli/commands/list/list-stacks.mdx
🚧 Files skipped from review as they are similar to previous changes (13)
- internal/exec/describe_stacks_yaml_function_hints.go
- website/docs/cli/commands/list/list-components.mdx
- internal/exec/describe_stacks_component_processor.go
- website/docs/cli/commands/list/list-instances.mdx
- website/docs/cli/commands/list/list-dependencies.mdx
- internal/exec/describe_stacks_yaml_function_hints_test.go
- cmd/list/instances.go
- cmd/list/dependencies.go
- cmd/list/components.go
- cmd/list/stacks.go
- website/docs/cli/commands/list/list-stacks.mdx
- cmd/list/utils.go
- cmd/list/inventory_credentialed_functions_test.go
|
Code RabBit (@CodeRabbit) review |
✅ Action performedReview finished.
|
`atmos list stacks --identity <one-account>` aborted with an S3 AccessDenied reading *another* account's state bucket. The skip that keeps inventory commands away from credentialed YAML functions was gated on the AuthManager being nil, so passing `--identity` turned the reads back on — but an identity authenticates one account while the scan still spans every stack in every account, so no identity can ever succeed. The resolved values were discarded anyway: `list stacks` / `list components` project the describe result down to stack and component names. - Make `skipCredentialBackedYAMLFunctionsForInventory` unconditional, so `list stacks`, `list components`, `list dependencies` and `list instances` never evaluate `!terraform.state`, `!terraform.output`, `!store`, `!store.get`, `!secret` or `!aws.*`. Inventory output no longer depends on whether `--identity` happened to be supplied. - Split `executeAndExtractComponents` out of `initAndExtractComponents` so the describe/extract half is drivable with an injected AuthManager, mirroring `executeAndExtractStacks`. - An unfiltered `atmos describe stacks` legitimately resolves these functions, but hits the same wall across accounts. Attach actionable hints (`--stack`, `--skip terraform.state`, `--process-functions=false`) to that failure, guarded so a scoped run or a `list` caller never sees them. - Document the behavior on the affected command pages and record the analysis in docs/fixes/. Fixes cloudposse#2566 Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01UtnSvasDtm8t3pWAdvX9ex
Addresses review feedback on cloudposse#2820. The previous revision skipped credential-backed YAML functions unconditionally for inventory commands. That was too blunt: list output is customizable and can legitimately render these values, so resolution must be demand-driven rather than disabled. `skipCredentialBackedYAMLFunctionsForInventory` now takes an `outputCanSurfaceValues` flag and returns the caller's `--skip` untouched when true. Each command answers from what it was actually asked to render: - `list stacks` / `list components`: custom `--columns` or a `list.*.columns` block in atmos.yaml - `list dependencies`: never — it renders a fixed graph of component/stack names - `list instances`: `--columns`, `--query`, `--filter`, or `--upload` The test is conservative: any customization counts, because Atmos cannot know whether `{{ .vars.x }}` came from a YAML function without resolving it first. Only the built-in default columns, which render identity fields Atmos derives itself, are provably value-free. That fixes the reported command (plain `atmos list stacks`) while leaving customized output working as before. Also from review: - Fix `resolvesTerraformStateFunctions`, which suppressed the describe-stacks hints when *either* terraform function was skipped. A partial skip still resolves the other against a remote backend, so the guidance must survive; only skipping both is credential-free. Table-driven test added. - Replace the tautological skip-set assertion with an independent expected list, so removing a function from the helper now fails the test. - Terminate inline comments with periods (godot) and document the remaining test helpers. Adds `TestExecuteAndExtractStacks_ResolvesWhenColumnsAreCustomized` as the negative path, so a regression back to an unconditional skip fails the build. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01UtnSvasDtm8t3pWAdvX9ex
Addresses the remaining CodeRabbit nitpick on cloudposse#2820: stacks and components each had full cross-account fixture coverage (authenticated success plus a customized-output negative path) while `list instances` only had the predicate-level test, despite having the largest value-surfacing surface (--query, --filter, --upload). The new tests drive the real executeListInstancesCmd by swapping the listAuthManagerFactory seam cloudposse#2801 introduced, so they exercise the production skip wiring rather than re-deriving it in the test. The negative path is table-driven over --query, --filter and --columns. Both instances and stacks negative paths now assert errors.Is(err, ErrDescribeComponent) rather than merely requiring an error. Confirmed that is the real cause, so a malformed query or column template can no longer satisfy the test while proving nothing about resolution. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01UtnSvasDtm8t3pWAdvX9ex
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2820 +/- ##
==========================================
+ Coverage 82.76% 82.78% +0.01%
==========================================
Files 1861 1862 +1
Lines 180478 180496 +18
==========================================
+ Hits 149380 149415 +35
+ Misses 23311 23292 -19
- Partials 7787 7789 +2
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
…generated mock Addresses the latest CodeRabbit round on cloudposse#2820. - Gate explainRepositoryWideYAMLFunctionFailure on p.onWarning == nil. A non-nil onWarning means warn/silent mode, where the lead hint "drop --error-mode=strict" is nonsense advice — reaching the helper in warn mode means the error was non-recoverable, which no error mode fixes. - Correct the --stack hint and the describe-stacks docs, which claimed scoping avoids the cross-account reads. It does not: --stack narrows which components are evaluated, but a !terraform.state inside the selected stack can still name a component in another stack and account — which is exactly the shape cloudposse#2566 reported. - Replace the hand-written failingStateGetter with the generated MockTerraformStateGetter, per the repo's mockgen rule. MinTimes(1) now enforces that the state read was attempted, which the manual double asserted separately; that property is what distinguishes degrading a failed read from skipping it. Adds tests for both new behaviors: no hints in warn mode, and the --stack hint stating its real effect. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01UtnSvasDtm8t3pWAdvX9ex
Self-review of the PR surfaced a gap and two stale comments. !terraform.output is NOT covered by this fix. It shells out to `terraform output` and wraps every subprocess failure in ErrTerraformOutputFailed — missing binary, HCL error, timeout, and access denial alike — so it never produces ErrReadTerraformState and never reaches the widened classifier. Degrading that error wholesale would hide real defects, so it stays strict. The describe-stacks docs said "values Atmos cannot read are degraded", which over-promised; both the docs and the classifier comment now state the scope, and the fix doc records closing the gap as follow-up. Also: - The hint helper's doc comment still described a skipped-state caller as "an inventory `list` command, which never performs these reads" — true only of the reverted revision. Reworded to describe the actual condition. - The fix doc still credited `getter.calls > 0` for proving the read was attempted; that assertion moved to the generated mock's MinTimes(1). No behavior change. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01UtnSvasDtm8t3pWAdvX9ex
|
thejrose1984 thanks for the PR, please review the failing tests |
The fix doc claimed all cmd/list changes were reverted and that `atmos list stacks` always attempts every cross-account read. Neither matches the shipped behavior: the demand-driven guard `skipCredentialBackedYAMLFunctionsForInventory` keeps built-in identity-only inventory output credential-free, and reads run only when a view (explicit --identity, or a custom column/query/filter/upload) asks for a credential-backed value. Reword "What this replaces" and the cost recommendation to reflect that, keeping the classifier-degradation explanation intact. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Yes, I think so - we want the list/describe commands to gracefully degrade unless |
`isRecoverableInWarnMode` accepted all of `ErrReadTerraformState`, but `GetTerraformState` wraps that sentinel around every backend failure, including four that are defects in the stack manifests rather than conditions of the environment. In warn/silent mode (the default) a typo'd `backend_type`, a corrupt state file, a `static` backend missing the requested output, and a bad YQ expression all rendered as `(computed)` and exited 0, turning a typo into a plausible-looking value with no signal that anything was wrong. - Wrap the cause with `%w` instead of `%v` in `GetTerraformState` so `errors.Is` can reach the real sentinel. The static "output does not exist" case gains `ErrStaticRemoteStateOutputMissing`, which it never had. - Subtract those four sentinels from `isRecoverableInWarnMode`. Environmental failures — cross-account `AccessDenied`, unreachable or unprovisioned backends — still degrade, so cloudposse#2566 stays fixed. - Gate the `describe stacks` hints on `isRecoverableInWarnMode` rather than on strict mode alone. Every hint is a way to stop Atmos failing on an unreadable backend, and the lead one promises that dropping `--error-mode=strict` lets the command continue; for a circular `!terraform.state` chain that is false, and the five suggestions buried the cycle's own remediation. - Fix `TestExplainRepositoryWideYAMLFunctionFailure_PreservesWrappedSentinels`, which asserted only `errors.Is` and so passed whether or not hints were attached. Co-Authored-By: Claude Opus 5 <[email protected]>
|
Code RabBit (@CodeRabbit) review |
✅ Action performedReview finished.
|
|
Note GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer. |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@docs/fixes/2026-07-28-inventory-commands-read-remote-tfstate.md`:
- Around line 92-101: Update the explanation around ErrReadTerraformState to
distinguish the error paths in GetTerraformState: describe
ErrUnsupportedBackendType, ErrProcessTerraformStateFile, and
ErrStaticRemoteStateOutputMissing as defects wrapped by ErrReadTerraformState,
while describing ErrEvaluateTerraformBackendVariable as a separate post-read
manifest defect returned after state retrieval. Keep the table’s fatality
rationale and align the wording with internal/exec/terraform_state_utils.go.
In `@internal/exec/yaml_func_utils_lenient_test.go`:
- Around line 200-225: Update the comments and test description in
TestProcessCustomYamlTagsLenient_WrappedCredentialFailure_Warn to reflect that
GetTerraformState wraps backend causes with %w, rather than claiming inner
sentinels are lost through %v. Describe the limitation as the current
environmental error contract not distinguishing credential-source failures from
cross-account access failures, while preserving the distinction for
manifest-defect sentinels.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 17ec0802-0c5b-4931-8825-c612b5895355
📒 Files selected for processing (11)
docs/fixes/2026-07-28-inventory-commands-read-remote-tfstate.mderrors/errors.gointernal/exec/describe_stacks_component_processor.gointernal/exec/describe_stacks_yaml_function_hints.gointernal/exec/describe_stacks_yaml_function_hints_test.gointernal/exec/terraform_state_utils.gointernal/exec/yaml_func_terraform_state.gointernal/exec/yaml_func_terraform_state_degradation_test.gointernal/exec/yaml_func_terraform_state_yq_defaults_test.gointernal/exec/yaml_func_utils_lenient_test.gowebsite/docs/cli/commands/describe/describe-stacks.mdx
🚧 Files skipped from review as they are similar to previous changes (2)
- internal/exec/describe_stacks_component_processor.go
- internal/exec/yaml_func_terraform_state_yq_defaults_test.go
| `ErrReadTerraformState` is not a synonym for "environmental failure". `GetTerraformState` | ||
| wraps it around *everything* `GetTerraformBackend` and the static-backend path can return, | ||
| which includes four failures that are unambiguously mistakes in the stack manifests: | ||
|
|
||
| | Failure | Sentinel | Why it must stay fatal | | ||
| | --- | --- | --- | | ||
| | `backend_type` names a backend Atmos does not implement | `ErrUnsupportedBackendType` | A typo; no error mode makes it work. | | ||
| | Retrieved state is not parseable Terraform state | `ErrProcessTerraformStateFile` | Degrading hides state corruption. | | ||
| | A `static` backend does not declare the requested output | `ErrStaticRemoteStateOutputMissing` | The outputs are written in the manifest; a missing key is a typo. | | ||
| | The YQ expression failed against state Atmos *did* retrieve | `ErrEvaluateTerraformBackendVariable` | The read succeeded; the expression is wrong. | |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Separate ErrEvaluateTerraformBackendVariable from the ErrReadTerraformState wrapper.
GetTerraformState wraps backend and static-backend read failures with ErrReadTerraformState. It returns ErrEvaluateTerraformBackendVariable later, after state retrieval, when it evaluates the requested output. That error is not nested in ErrReadTerraformState.
Update this explanation so the first three table entries are described as wrapped read defects, while the fourth is described as a separate post-read manifest defect. This keeps the fix log aligned with internal/exec/terraform_state_utils.go.
Suggested wording
-`ErrReadTerraformState` is not a synonym for "environmental failure". `GetTerraformState`
-wraps it around *everything* `GetTerraformBackend` and the static-backend path can return,
-which includes four failures that are unambiguously mistakes in the stack manifests:
+`ErrReadTerraformState` is not a synonym for "environmental failure". `GetTerraformState`
+wraps it around backend and static-backend read failures, including the first three
+failures below. `ErrEvaluateTerraformBackendVariable` is returned separately after
+state retrieval when the requested output expression is invalid:📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| `ErrReadTerraformState` is not a synonym for "environmental failure". `GetTerraformState` | |
| wraps it around *everything* `GetTerraformBackend` and the static-backend path can return, | |
| which includes four failures that are unambiguously mistakes in the stack manifests: | |
| | Failure | Sentinel | Why it must stay fatal | | |
| | --- | --- | --- | | |
| | `backend_type` names a backend Atmos does not implement | `ErrUnsupportedBackendType` | A typo; no error mode makes it work. | | |
| | Retrieved state is not parseable Terraform state | `ErrProcessTerraformStateFile` | Degrading hides state corruption. | | |
| | A `static` backend does not declare the requested output | `ErrStaticRemoteStateOutputMissing` | The outputs are written in the manifest; a missing key is a typo. | | |
| | The YQ expression failed against state Atmos *did* retrieve | `ErrEvaluateTerraformBackendVariable` | The read succeeded; the expression is wrong. | | |
| `ErrReadTerraformState` is not a synonym for "environmental failure". `GetTerraformState` | |
| wraps it around backend and static-backend read failures, including the first three | |
| failures below. `ErrEvaluateTerraformBackendVariable` is returned separately after | |
| state retrieval when the requested output expression is invalid: | |
| | Failure | Sentinel | Why it must stay fatal | | |
| | --- | --- | --- | | |
| | `backend_type` names a backend Atmos does not implement | `ErrUnsupportedBackendType` | A typo; no error mode makes it work. | | |
| | Retrieved state is not parseable Terraform state | `ErrProcessTerraformStateFile` | Degrading hides state corruption. | | |
| | A `static` backend does not declare the requested output | `ErrStaticRemoteStateOutputMissing` | The outputs are written in the manifest; a missing key is a typo. | | |
| | The YQ expression failed against state Atmos *did* retrieve | `ErrEvaluateTerraformBackendVariable` | The read succeeded; the expression is wrong. | |
🧰 Tools
🪛 LanguageTool
[typographical] ~92-~92: Consider using typographic quotation marks here.
Context: ...eadTerraformStateis not a synonym for "environmental failure".GetTerraformState` wraps it around *e...
(EN_QUOTES)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@docs/fixes/2026-07-28-inventory-commands-read-remote-tfstate.md` around lines
92 - 101, Update the explanation around ErrReadTerraformState to distinguish the
error paths in GetTerraformState: describe ErrUnsupportedBackendType,
ErrProcessTerraformStateFile, and ErrStaticRemoteStateOutputMissing as defects
wrapped by ErrReadTerraformState, while describing
ErrEvaluateTerraformBackendVariable as a separate post-read manifest defect
returned after state retrieval. Keep the table’s fatality rationale and align
the wording with internal/exec/terraform_state_utils.go.
| // TestProcessCustomYamlTagsLenient_WrappedCredentialFailure_Warn documents a real consequence | ||
| // of the #2566 fix that deserves explicit sign-off: because GetTerraformState collapses every | ||
| // backend failure into ErrReadTerraformState (formatting the cause with %v, so no inner | ||
| // sentinel survives), warn mode cannot tell a cross-account AccessDenied — which must degrade — | ||
| // from a broken credential source such as an expired SSO session, which arguably should stay | ||
| // loud. Both now degrade to `(computed)`. | ||
| // | ||
| // This is the intended trade for making multi-account listing work at all; `--error-mode=strict` | ||
| // still surfaces both. Distinguishing them would require preserving the AWS error code up | ||
| // through the S3 backend (terraform_backend_s3.go also uses %v) and is tracked as follow-up. | ||
| func TestProcessCustomYamlTagsLenient_WrappedCredentialFailure_Warn(t *testing.T) { | ||
| ctrl := gomock.NewController(t) | ||
| defer ctrl.Finish() | ||
|
|
||
| mockStateGetter := NewMockTerraformStateGetter(ctrl) | ||
| originalGetter := stateGetter | ||
| stateGetter = mockStateGetter | ||
| defer func() { stateGetter = originalGetter }() | ||
|
|
||
| atmosConfig := &schema.AtmosConfiguration{BasePath: t.TempDir()} | ||
|
|
||
| // Exactly how GetTerraformState wraps a backend failure before the classifier sees it. | ||
| wrapped := fmt.Errorf( | ||
| "%w for component `vpc` in stack `test-stack`\nin YAML function: `!terraform.state vpc test-stack bucket_name`\n"+ | ||
| "failed to get object from S3: get identity: get credentials: failed to refresh cached credentials, no EC2 IMDS role found", | ||
| errUtils.ErrReadTerraformState, |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Correct the error-wrapping description.
GetTerraformState now wraps backend causes with %w in internal/exec/terraform_state_utils.go Line 192. These comments say it formats causes with %v and loses inner sentinels. That is no longer true.
State that warn mode cannot distinguish credential-source failures from cross-account access failures with the current environmental error contract. Keep the distinction from preserved manifest-defect sentinels clear.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@internal/exec/yaml_func_utils_lenient_test.go` around lines 200 - 225, Update
the comments and test description in
TestProcessCustomYamlTagsLenient_WrappedCredentialFailure_Warn to reflect that
GetTerraformState wraps backend causes with %w, rather than claiming inner
sentinels are lost through %v. Describe the limitation as the current
environmental error contract not distinguishing credential-source failures from
cross-account access failures, while preserving the distinction for
manifest-defect sentinels.
|
💥 This pull request now has conflicts. Could you fix it thejrose1984? 🙏 |
Quality Gate
Readiness✅ Fewer than 150 changed files ReviewsMeasuresCurrent commit: Quality Gate details
🤖 Next steps for this PR |
atmos list stacks --identity <one-account>aborted with an S3 AccessDenied reading another account's state bucket. The skip that keeps inventory commands away from credentialed YAML functions was gated on the AuthManager being nil, so passing--identityturned the reads back on — but an identity authenticates one account while the scan still spans every stack in every account, so no identity can ever succeed.The resolved values were discarded anyway:
list stacks/list componentsproject the describe result down to stack and component names.skipCredentialBackedYAMLFunctionsForInventoryunconditional, solist stacks,list components,list dependenciesandlist instancesnever evaluate!terraform.state,!terraform.output,!store,!store.get,!secretor!aws.*. Inventory output no longer depends on whether--identityhappened to be supplied.executeAndExtractComponentsout ofinitAndExtractComponentsso the describe/extract half is drivable with an injected AuthManager, mirroringexecuteAndExtractStacks.atmos describe stackslegitimately resolves these functions, but hits the same wall across accounts. Attach actionable hints (--stack,--skip terraform.state,--process-functions=false) to that failure, guarded so a scoped run or alistcaller never sees them.Fixes #2566
Claude-Session: https://claude.ai/code/session_01UtnSvasDtm8t3pWAdvX9ex
what
why
references
Summary by CodeRabbit
Bug Fixes
atmos list stacksandatmos describe stacksbehavior when remote Terraform state cannot be accessed.(computed), while strict mode still reports failures.Documentation