Repository navigation
Fix terraform backend subcommands not recognizing --stack - #2508
Andriy Knysh (aknysh) merged 12 commits into
Conversation
|
Tip Atmos Pro
No affected stacks workflow was detected for this pull request. |
--stack
Dependency Review✅ No vulnerabilities or license issues found.Scanned FilesNone |
|
CodeRabbit (@coderabbitai) this does not appear like correct flag handling using our flag handler. Especially for identity. Can you confirm? |
|
Tip For best results, initiate chat on the files or code changes. 🧩 Analysis chainLet me examine the existing flag handling patterns and the new code in this PR. 🏁 Script executed: Length of output: 5257 🏁 Script executed: Length of output: 63477 🏁 Script executed: Length of output: 1747 🏁 Script executed: Length of output: 20237 🏁 Script executed: Length of output: 13804 🏁 Script executed: Length of output: 16268 🏁 Script executed: Length of output: 7629
1. Missing
|
Codecov Report❌ Patch coverage is ❌ Your patch check has failed because the patch coverage (75.60%) is below the target coverage (85.00%). You can increase the patch coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## main #2508 +/- ##
==========================================
+ Coverage 81.85% 81.89% +0.04%
==========================================
Files 1715 1719 +4
Lines 161896 162175 +279
==========================================
+ Hits 132521 132818 +297
+ Misses 22139 22097 -42
- Partials 7236 7260 +24
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
…ul degradation - Continue the terraform backend subcommand stack-flag fix: tighten flag_values parsing/validation and simplify backend_create/delete/describe/list/update and their tests around the new flag handling. - Add `--on-error=warn` for `list stacks/components/settings` so a recoverable !terraform.state/!terraform.output failure (unprovisioned backend) degrades to null with a warning instead of aborting the whole listing; default `strict` behavior is unchanged. See docs/fixes/2026-07-13-list-on-error-graceful-degradation.md. - Add a backend-provisioning example/demo cast illustrating the new behavior.
55f180c to
f074dea
Compare
|
Important Cloud Posse Engineering Team Review RequiredThis pull request modifies files that require Cloud Posse's review. Please be patient, and a core maintainer will review your changes. To expedite this process, reach out to us on Slack in the |
|
💥 This pull request now has conflicts. Could you fix it @Copilot? 🙏 |
…raform-backend-subcommands # Conflicts: # cmd/list/components.go
|
💥 This pull request now has conflicts. Could you fix it @Copilot? 🙏 |
…raform-backend-subcommands # Conflicts: # pkg/git/git.go
|
CodeRabbit (@coderabbitai) review |
✅ Action performedReview finished.
|
📝 WalkthroughWalkthroughThe change adds configurable graceful degradation for ChangesGraceful degradation
Estimated code review effort: 5 (Critical) | ~120 minutes Sequence Diagram(s)sequenceDiagram
participant CLI
participant ListDescribeCommand
participant DescribeStacks
participant YAMLResolver
participant Collector
CLI->>ListDescribeCommand: provide error-mode
ListDescribeCommand->>DescribeStacks: resolve options and execute
DescribeStacks->>YAMLResolver: resolve YAML functions
YAMLResolver->>Collector: record recoverable warning
YAMLResolver-->>DescribeStacks: return computed value
DescribeStacks-->>ListDescribeCommand: render output
ListDescribeCommand->>Collector: print warn summary
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 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: 12
🧹 Nitpick comments (3)
examples/backend-provisioning/components/terraform/bucket/variables.tf (1)
1-3: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueSpecify the variable type.
It is good practice to explicitly define the
typefor Terraform variables to ensure proper validation and clarity, even in examples.💡 Proposed fix
variable "stage" { + type = string description = "The stage of the environment (e.g. dev, staging, prod)" }🤖 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 `@examples/backend-provisioning/components/terraform/bucket/variables.tf` around lines 1 - 3, Update the Terraform variable declaration for "stage" to explicitly specify its type as a string, preserving the existing description.cmd/terraform/backend/flag_values_test.go (1)
11-83: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueConvert to table-driven tests.
The tests look good and properly isolate standard Cobra flag evaluation behavior. However, to fully align with the repository guidelines, consider refactoring these sequential
t.Runblocks into a single slice of structs (table-driven design).It's completely fine if you prefer to keep this as-is for these simple structural tests, but a table-driven approach scales better if more edge cases are added later.
🤖 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/terraform/backend/flag_values_test.go` around lines 11 - 83, Refactor TestGetCommandFlagString and TestGetCommandFlagBool into table-driven tests using slices of case structs, with each case retaining its command setup, expected value, and changed state. Execute cases through a loop with t.Run, preserving the existing local, inherited, unchanged, and missing-flag coverage and assertions.Source: Coding guidelines
cmd/list/settings.go (1)
73-77: 🎯 Functional Correctness | 🔵 Trivial | 💤 Low valueAvoid printing an extra newline on empty output.
If
listSettingsWithOptionsencounters aNoValuesFoundError, it returns an empty string foroutput. Passing this empty string todata.Writeln(output)below will print an unwanted extra newline to stdout, diverging from the previous behavior wheredata.Writelnwas skipped entirely on empty results.🛠️ Proposed fix
if err != nil { return err } defer printErrorModeSummary(opts.ErrorMode, collector) - return data.Writeln(output) + if output != "" { + return data.Writeln(output) + } + return nil },🤖 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/settings.go` around lines 73 - 77, Guard the output-writing call after listSettingsWithOptions so data.Writeln is invoked only when output is non-empty. Preserve the existing error return and printErrorModeSummary behavior, while keeping empty NoValuesFoundError results from emitting a newline.
🤖 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/error_mode_test.go`:
- Around line 53-75: Strengthen TestPrintErrorModeSummary by injecting or
capturing the UI output writer, then assert that printErrorModeSummary emits the
expected warning summary for "warn" and emits no output for "silent" even when
warnings exist. Keep the strict nil-collector case, but ensure the warn and
silent subtests validate observable output rather than only absence of panics.
In `@cmd/list/settings.go`:
- Around line 176-181: Update the NoValuesFoundError handling in the surrounding
settings retrieval function to return the existing collector alongside the empty
output and nil error, rather than discarding it. Preserve the current error
return behavior for other errors and the normal output, collector, nil result
path.
In `@cmd/terraform/backend/backend_create.go`:
- Around line 40-43: The backend commands bypass normalized identity parsing by
directly reading the raw flag. In
cmd/terraform/backend/backend_create.go#L40-L43, use the normalized identity
returned by flags.ParseGlobalFlags(cmd, v); in
cmd/terraform/backend/backend_delete.go#L44-L47,
cmd/terraform/backend/backend_describe.go#L44-L47, and
cmd/terraform/backend/backend_update.go#L43-L46, remove the direct identity
pre-read so all commands preserve IdentitySelector normalization and parent
persistent flags.
In `@cmd/terraform/backend/backend_helpers_test.go`:
- Around line 75-89: The test
TestInitConfigAndAuth_FailsWhenAuthConfiguredButIdentityMissing must cover a
missing identity within configured authentication. Update its fixture or setup
to define auth with at least one identity, then pass a different nonexistent
identity and assert the intended identity-resolution error; otherwise rename the
test to reflect the ErrAuthNotConfigured scenario it currently exercises.
In `@cmd/terraform/backend/backend_list.go`:
- Around line 27-45: Update the backend list command to retain and consume the
ParsedConfig returned by listParser.Parse instead of rebuilding stack, identity,
and format through getCommandFlagString and Viper. Use the resolved values from
ParsedConfig so prompted values, parser precedence, and IdentitySelector
normalization are preserved, while continuing to process command-specific flags
through flags.NewStandardParser().
In `@cmd/terraform/backend/flag_values.go`:
- Around line 9-38: Update the identity flag handling in the relevant caller of
getCommandFlagString so it uses the parsed result.Flags.Identity (or parsed
global flags) rather than reading cmd.Flags() directly. Preserve normalized
boolean parsing so values such as false, 0, no, and off disable authentication
instead of being treated as literal identity values.
In `@demo/casts/atmos.d/examples/backend-provisioning/lifecycle.yaml`:
- Around line 84-89: Update the two re.sub regexes in the lifecycle sanitization
step to use correctly escaped raw-string patterns: match the literal registry
dots with \. and the tab delimiters with \t, so both the digest and runtime
container value are replaced in the generated cast.
In `@internal/exec/describe_stacks_test.go`:
- Around line 354-389: Strengthen the PrintErrorModeSummary tests to assert
observable output and warning metadata, not just panic safety or collection
length. Capture the relevant UI/stderr output for warn, silent, and strict
modes, verify the expected DegradationWarning fields and slice contents, and
update strict-mode assertions to require.ErrorIs(err,
errUtils.ErrTerraformStateNotProvisioned) while preserving no-output behavior
where required.
In `@internal/exec/describe_stacks.go`:
- Around line 214-220: Make warn-mode summary printing nil-safe by requiring a
non-nil collector before calling Summary() in exec.PrintErrorModeSummary; update
internal/exec/describe_stacks.go lines 214-220 accordingly. Also update
cmd/list/error_mode.go lines 34-39 to delegate to exec.PrintErrorModeSummary or
apply the same collector guard, preserving summary output when a collector
exists.
- Around line 18-20: Move the sentinel definition for ErrInvalidErrorMode from
the exec package into the shared errors/errors.go catalog, then expose the
exec-level ErrInvalidErrorMode as an alias to that shared sentinel to preserve
existing callers. Update references as needed so all paths compare against the
same error value.
In `@internal/exec/yaml_func_utils.go`:
- Around line 55-77: The lenient path must remain active when onWarning is nil;
normalize nil to a no-op callback before processNodesWithContext in
ProcessCustomYamlTagsLenient, while preserving silent degradation. Add a
regression case in internal/exec/yaml_func_utils_lenient_test.go:46-89 verifying
that a recoverable error with a nil callback yields
degradation.AtmosComputedValue{} and does not fail processing.
In `@website/docs/cli/commands/list/list-stacks.mdx`:
- Around line 125-128: Update the list-stacks documentation for the
error-handling option to use the implemented flag name --error-mode and
environment variable ATMOS_LIST_ERROR_MODE instead of --on-error and
ATMOS_LIST_ON_ERROR, while preserving the existing strict and warn behavior
descriptions.
---
Nitpick comments:
In `@cmd/list/settings.go`:
- Around line 73-77: Guard the output-writing call after listSettingsWithOptions
so data.Writeln is invoked only when output is non-empty. Preserve the existing
error return and printErrorModeSummary behavior, while keeping empty
NoValuesFoundError results from emitting a newline.
In `@cmd/terraform/backend/flag_values_test.go`:
- Around line 11-83: Refactor TestGetCommandFlagString and
TestGetCommandFlagBool into table-driven tests using slices of case structs,
with each case retaining its command setup, expected value, and changed state.
Execute cases through a loop with t.Run, preserving the existing local,
inherited, unchanged, and missing-flag coverage and assertions.
In `@examples/backend-provisioning/components/terraform/bucket/variables.tf`:
- Around line 1-3: Update the Terraform variable declaration for "stage" to
explicitly specify its type as a string, preserving the existing description.
🪄 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
Run ID: 2d321d4b-cba1-476d-83ae-7c9034b7008b
📒 Files selected for processing (76)
.github/workflows/test.ymlcmd/describe_affected.gocmd/describe_affected_test.gocmd/describe_dependents.gocmd/describe_dependents_test.gocmd/describe_error_mode_flag.gocmd/describe_error_mode_flag_test.gocmd/describe_stacks.gocmd/describe_stacks_test.gocmd/list/affected.gocmd/list/components.gocmd/list/error_mode.gocmd/list/error_mode_test.gocmd/list/flag_wrappers.gocmd/list/parse_options_test.gocmd/list/settings.gocmd/list/stacks.gocmd/terraform/backend/backend_commands_test.gocmd/terraform/backend/backend_create.gocmd/terraform/backend/backend_delete.gocmd/terraform/backend/backend_describe.gocmd/terraform/backend/backend_helpers.gocmd/terraform/backend/backend_helpers_test.gocmd/terraform/backend/backend_list.gocmd/terraform/backend/backend_update.gocmd/terraform/backend/flag_values.gocmd/terraform/backend/flag_values_test.godemo/casts/atmos.d/examples/backend-provisioning/lifecycle.yamldemo/casts/atmos.yamldocs/fixes/2026-07-13-list-on-error-graceful-degradation.mdexamples/README.mdexamples/backend-provisioning/.gitignoreexamples/backend-provisioning/README.mdexamples/backend-provisioning/atmos.yamlexamples/backend-provisioning/components/terraform/bucket/.terraform.lock.hclexamples/backend-provisioning/components/terraform/bucket/main.tfexamples/backend-provisioning/components/terraform/bucket/outputs.tfexamples/backend-provisioning/components/terraform/bucket/variables.tfexamples/backend-provisioning/components/terraform/bucket/versions.tfexamples/backend-provisioning/schemas/atmos-manifest.jsonexamples/backend-provisioning/stacks/catalog/demo.yamlexamples/backend-provisioning/stacks/catalog/emulator/aws.yamlexamples/backend-provisioning/stacks/deploy/dev/demo.yamlexamples/backend-provisioning/stacks/deploy/prod/demo.yamlexamples/backend-provisioning/stacks/deploy/staging/demo.yamlinternal/exec/describe_affected.gointernal/exec/describe_affected_authdisabled_test.gointernal/exec/describe_affected_helpers.gointernal/exec/describe_affected_test.gointernal/exec/describe_affected_utils.gointernal/exec/describe_affected_utils_2.gointernal/exec/describe_affected_utils_test.gointernal/exec/describe_dependents.gointernal/exec/describe_stacks.gointernal/exec/describe_stacks_component_processor.gointernal/exec/describe_stacks_component_processor_test.gointernal/exec/describe_stacks_test.gointernal/exec/yaml_func_utils.gointernal/exec/yaml_func_utils_context_test.gointernal/exec/yaml_func_utils_lenient_test.gopkg/datafetcher/schema/config/global/1.0.jsonpkg/degradation/degradation.gopkg/degradation/degradation_test.gopkg/flags/standard.gopkg/flags/standard_test.gopkg/list/column/column_test.gopkg/list/format/table.gopkg/list/format/table_test.gopkg/list/list_affected.gopkg/schema/schema.gowebsite/blog/2025-11-20-automatic-backend-provisioning.mdxwebsite/blog/2026-07-13-list-describe-graceful-degradation.mdxwebsite/docs/cli/commands/list/list-components.mdxwebsite/docs/cli/commands/list/list-settings.mdxwebsite/docs/cli/commands/list/list-stacks.mdxwebsite/static/casts/examples/backend-provisioning/lifecycle.cast
|
Tip Atmos Pro
No affected stacks workflow was detected for this pull request. |
|
These changes were released in v1.223.0. |
atmos terraform backendsubcommands were rejecting invocations with--stackas “required flag not provided,” even when the flag was explicitly passed. This occurred because backend command parsing relied on parsed positional args/Viper state that did not consistently reflect subcommand CLI flag values.Root cause and behavior correction
--stack(and related flags) from being dropped during backend subcommand execution.Backend command updates
create,update,delete,describe, andlistRunEhandlers to:Shared flag-resolution helper
cmd/terraform/backend/flag_values.gowith reusable helpers to read changed string/bool flags from local/inherited command flags, enabling consistent behavior across backend subcommands.Regression coverage
--stackis provided and that the resolved value flows into backend config initialization.Summary by CodeRabbit
--error-modehandling for list and describe commands, supportingstrict,warn, andsilent.(computed)values with optional summaries.