Skip to content

Fix authentication in YAML template functions and add --identity flag to describe commands#1742

Merged
aknysh merged 9 commits intomainfrom
fix-auth-terraform-state
Nov 3, 2025
Merged

Fix authentication in YAML template functions and add --identity flag to describe commands#1742
aknysh merged 9 commits intomainfrom
fix-auth-terraform-state

Conversation

@aknysh
Copy link
Member

@aknysh aknysh commented Nov 3, 2025

what

  • Fixed critical authentication bug where !terraform.state and !terraform.output YAML template functions failed to access authenticated credentials when using the --identity flag
  • Added --identity flag support to all atmos describe commands (describe stacks, describe component, describe affected, describe dependents)
  • Thread AuthContext from AuthManager through the entire component description pipeline, enabling template functions to access authenticated credentials for remote state backends (S3, Azure Blob, GCS)
  • Added authentication configuration validation to prevent confusing errors when --identity is used without auth configured in atmos.yaml
  • Created comprehensive tests for AuthManager propagation and identity flag handling
  • Refactored ExecuteDescribeComponent to use parameter struct pattern for cleaner API

why

Problem 1: Template Functions Authentication Failure

Users reported that !terraform.state and !terraform.output template functions failed with "context deadline exceeded" errors when using the --identity flag:

$ atmos terraform apply runs-on -s core-use2-auto --identity core-auto/terraform
Error: context deadline exceeded (accessing S3 without credentials)

The workaround of running atmos terraform output worked fine with the same identity, indicating the credentials were being authenticated but not propagated to template function processing.

Root Cause: The authentication context was not being threaded from AuthManager to the YAML function processors. When ExecuteDescribeComponent was called, it didn't receive the AuthManager, so configAndStacksInfo.AuthContext remained nil, causing template functions to fail when accessing remote state.

Problem 2: Missing Identity Support for Describe Commands

The atmos describe family of commands (describe stacks, describe component, describe affected, describe dependents) can execute YAML template functions that require authentication, but had no way to authenticate at runtime. Users were forced to:

  • Manually run atmos auth login --identity <identity> before describe commands
  • Rely on ambient AWS credentials (environment variables, profiles)
  • Use EC2 instance profiles (not applicable for local development)

Problem 3: Confusing Error Messages

When users tried to use --identity without configuring the auth section in atmos.yaml, they received confusing authentication errors instead of clear guidance.

Solution:

  1. Thread AuthContext Through Pipeline:

    • Create stackInfo with AuthContext before creating AuthManager
    • Pass AuthManager through ExecuteDescribeComponent and related functions
    • Extract AuthContext from AuthManager and populate configAndStacksInfo
    • Template functions now access credentials via stackInfo.AuthContext
  2. Add --identity Flag to Describe Commands:

    • Added --identity as a PersistentFlag to parent describe command (auto-inherits to all subcommands)
    • Supports explicit identity: --identity my-identity
    • Supports interactive selection: --identity (no value)
    • Short form: -i my-identity
  3. Auth Configuration Validation:

    • Check if auth is configured when --identity flag is provided
    • Return clear error message if auth section is missing or empty
    • Allow commands to work normally without --identity (backward compatible)

Business Impact:

  • Fixes Critical Bug: Template functions now work correctly with identity-based authentication
  • Enables Multi-Account Workflows: Users can now use describe commands across multiple AWS accounts with proper authentication
  • Improves User Experience: Clear error messages guide users to configure authentication properly
  • Maintains Backward Compatibility: Existing workflows continue to work unchanged

references

Technical Documentation:

  • PRD: docs/prd/terraform-template-functions-auth-context.md - Details the authentication propagation fix
  • PRD: docs/prd/describe-commands-identity-flag.md - Documents the --identity flag feature for describe commands
  • Test Review: docs/test-review-auth-identity.md - Comprehensive test coverage analysis

Blog Post:

  • website/blog/2025-11-02-describe-commands-identity-flag.mdx - User-facing announcement of the new --identity flag feature

Key Changes:

  1. Authentication Context Propagation (terraform-template-functions-auth-context.md):

    • Modified cmd/cmd_utils.go to create stackInfo before AuthManager
    • Updated ExecuteDescribeComponent to accept AuthManager via parameter struct
    • Added AuthContext propagation in ExecuteDescribeComponentWithContext
    • Updated all 10+ callers to pass AuthManager
    • Created tests verifying AuthContext is available to template functions
  2. Describe Commands Identity Flag (describe-commands-identity-flag.md):

    • Added --identity flag to cmd/describe.go as PersistentFlag
    • Updated all describe subcommands to handle identity authentication
    • Created helper function CreateAuthManagerFromIdentity for centralized auth logic
    • Added auth configuration validation with clear error messages
    • Updated Docusaurus documentation for all describe commands
    • Created comprehensive blog post announcing the feature

Testing:

  • 20+ unit tests for AuthManager propagation across all describe commands
  • 4 new tests for ExecuteDescribeComponent with AuthManager
  • 4 tests for auth configuration validation
  • All existing tests pass (backward compatibility verified)
  • Manual testing confirmed template functions work with --identity

Documentation:

  • Updated all describe command documentation pages
  • Added usage examples with --identity flag
  • Created blog post for user announcement
  • Added error handling documentation

Summary by CodeRabbit

Release Notes

  • New Features

    • Added --identity flag to describe commands for authenticating YAML template functions that require access to remote resources
    • Support for interactive identity selection when flag is used without a value
    • Enhanced authentication capabilities for all describe subcommands
  • Documentation

    • Updated describe command documentation with identity flag usage examples
    • Published authentication guidance for YAML template processing

@aknysh aknysh added the minor New features that do not break anything label Nov 3, 2025
@aknysh aknysh requested review from a team as code owners November 3, 2025 01:30
@aknysh aknysh added the minor New features that do not break anything label Nov 3, 2025
@github-actions github-actions bot added the size/xl Extra large size PR label Nov 3, 2025
@mergify
Copy link

mergify bot commented Nov 3, 2025

Warning

This PR exceeds the recommended limit of 1,000 lines.

Large PRs are difficult to review and may be rejected due to their size.

Please verify that this PR does not address multiple issues.
Consider refactoring it into smaller, more focused PRs to facilitate a smoother review process.

@mergify
Copy link

mergify bot commented Nov 3, 2025

Important

Cloud Posse Engineering Team Review Required

This 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 #pr-reviews channel.

@mergify mergify bot added the needs-cloudposse Needs Cloud Posse assistance label Nov 3, 2025
@github-actions
Copy link

github-actions bot commented Nov 3, 2025

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 3, 2025

📝 Walkthrough

Walkthrough

This PR adds an --identity flag to atmos describe commands, enabling runtime authentication for YAML template functions that need credentials. It threads an AuthManager through describe command execution paths and refactors ExecuteDescribeComponent to accept a parameter struct instead of individual arguments.

Changes

Cohort / File(s) Summary
Configuration & Ignore Patterns
.gitignore
Added ignore patterns for test binaries (*.test, **/*.test) and backup files (*.bak, *.go.bak, **/*.go.bak).
License & Dependencies
NOTICE
Updated go.uber.org/mock/gomock URL from Unknown to concrete GitHub license URL.
Error Definitions
errors/errors.go
Added new error variable ErrAuthNotConfigured for authentication config validation.
Identity Flag Support
cmd/identity_flag.go, cmd/identity_flag_test.go
Introduced CreateAuthManagerFromIdentity function to create AuthManager from identity name; added test cases for nil auth config and missing identities.
Describe Command Setup
cmd/describe.go
Added persistent --identity / -i flag to describe command with interactive selection support via NoOptDefVal.
Command Utilities & Refactoring
cmd/cmd_utils.go
Updated NewAuthManager signature to accept *schema.ConfigAndStacksInfo; refactored ExecuteDescribeComponent to use new ExecuteDescribeComponentParams struct.
Describe Subcommand Implementations
cmd/describe_affected.go, cmd/describe_component.go, cmd/describe_dependents.go, cmd/describe_stacks.go
Integrated identity flag extraction and AuthManager creation/propagation into each subcommand's execution flow.
List Command Updates
cmd/list_components.go, cmd/list_metadata.go, cmd/list_settings.go, cmd/list_stacks.go, cmd/list_values.go
Updated ExecuteDescribeStacks call sites to pass additional nil parameters for AuthManager alignment.
Exec Layer: Core Component Description
internal/exec/describe_component.go, internal/exec/describe_component_test.go
Introduced ExecuteDescribeComponentParams struct; updated ExecuteDescribeComponent signature to accept single parameter object; wired AuthManager through execution context; added AuthContext population logic.
Exec Layer: Stack & Dependent Description
internal/exec/describe_stacks.go, internal/exec/describe_stacks_test.go, internal/exec/describe_affected.go, internal/exec/describe_affected_utils.go, internal/exec/describe_dependents.go
Added AuthManager field to execution arg structs; updated ExecuteDescribeStacks calls to pass AuthManager; propagated auth context through stack processing for Terraform, Helmfile, and Packer components.
Exec Layer: AuthManager Tests
internal/exec/describe_component_authmanager_test.go, internal/exec/describe_component_authmanager_propagation_test.go, internal/exec/describe_affected_authmanager_test.go, internal/exec/describe_dependents_authmanager_propagation_test.go, internal/exec/describe_stacks_authmanager_propagation_test.go
Added comprehensive tests validating AuthManager propagation, nil handling, and AuthContext extraction across describe workflows.
Exec Layer: Template Functions & Utilities
internal/exec/template_funcs.go, internal/exec/template_funcs_component.go, internal/exec/template_funcs_component_test.go, internal/exec/template_funcs_store_test.go, internal/exec/yaml_func_*.go
Updated componentFunc to receive configAndStacksInfo parameter; refactored all template function calls to use ExecuteDescribeComponentParams struct; added authContextWrapper for propagating auth context through Terraform output.
Exec Layer: Integration
internal/exec/atmos.go, internal/exec/abstract_component_backend_test.go, internal/exec/component_inheritance_test.go, internal/exec/stacks_processor.go, internal/exec/terraform_clean.go, internal/exec/terraform_output_utils.go, internal/exec/terraform_output_authcontext_wrapper_test.go, internal/exec/terraform_query.go, internal/exec/terraform_state_utils.go, internal/exec/validate_stacks.go, internal/exec/workflow_utils.go, internal/exec/yaml_func_circular_deps_test.go, internal/exec/yaml_func_utils_test.go
Updated all ExecuteDescribeStacks and ExecuteDescribeComponent call sites to use new signatures; added authStackInfo handling in workflow utils; introduced authContextWrapper for auth context propagation in Terraform output paths.
Package-Level Describe
pkg/describe/describe_component.go, pkg/describe/describe_component_test.go
Updated ExecuteDescribeComponent calls to use new struct-based parameter pattern.
Package-Level Hooks
pkg/hooks/hooks.go, pkg/hooks/hooks_component_scope_test.go
Refactored component execution calls to use ExecuteDescribeComponentParams.
Package-Level List
pkg/list/list_components_test.go, pkg/list/list_stacks_test.go, pkg/list/list_vendor.go, pkg/list/utils/utils.go, pkg/describe/describe_stacks.go
Updated ExecuteDescribeStacks calls to accommodate new parameter signatures.
Test Fixtures
tests/fixtures/scenarios/authmanager-propagation/README.md, tests/fixtures/scenarios/authmanager-propagation/atmos.yaml, tests/fixtures/scenarios/authmanager-propagation/stacks/test.yaml
Added test fixture directory with configuration and stack definitions for AuthManager propagation testing.
CLI Tests
tests/cli_describe_identity_test.go
Added CLI tests for describe commands with and without identity flag, including error paths for non-existent identities.
Test Snapshots
tests/snapshots/TestCLICommands_atmos_auth_whoami_without_authentication.stderr.golden
Minor whitespace formatting adjustment in auth whoami output snapshot.
Documentation: PRDs
docs/prd/describe-commands-identity-flag.md, docs/prd/terraform-template-functions-auth-context.md
Added comprehensive PRDs documenting identity flag feature, implementation approach, authentication flow, error handling, testing strategy, and migration guide.
Documentation: CLI Guides
website/docs/cli/commands/describe/describe-affected.mdx, website/docs/cli/commands/describe/describe-component.mdx, website/docs/cli/commands/describe/describe-dependents.mdx, website/docs/cli/commands/describe/describe-stacks.mdx
Updated command documentation with YAML functions/authentication information blocks, usage examples with --identity flag, and flag reference sections.
Documentation: Blog
website/blog/2025-11-02-describe-commands-identity-flag.mdx
Added blog post documenting new --identity flag support, usage modes, authentication flow, integration, and examples.

Sequence Diagram

sequenceDiagram
    participant User as CLI User
    participant CLI as Describe Command
    participant Flag as Flag Parser
    participant Auth as Auth Layer
    participant Mgr as AuthManager
    participant Exec as Executor
    participant YAML as YAML Processor
    
    User->>CLI: run describe --identity my-profile
    CLI->>Flag: Extract identity from flags
    Flag-->>Auth: identity name
    Auth->>Auth: Validate auth config exists
    Auth->>Mgr: CreateAuthManagerFromIdentity()
    Mgr-->>Auth: AuthManager (authenticated)
    Auth-->>CLI: AuthManager or error
    
    rect rgb(200, 220, 255)
    Note over CLI,YAML: With AuthManager set
    CLI->>Exec: ExecuteDescribeComponent(params with AuthManager)
    Exec->>Mgr: GetStackInfo() for AuthContext
    Mgr-->>Exec: ConfigAndStacksInfo with AuthContext
    Exec->>Exec: Populate configAndStacksInfo.AuthContext
    Exec->>YAML: Process templates/functions with credentials
    YAML-->>Exec: Results with authenticated access
    Exec-->>CLI: Component description
    end
    
    rect rgb(220, 220, 220)
    Note over CLI,YAML: Without AuthManager (backward compat)
    CLI->>Exec: ExecuteDescribeComponent(params, AuthManager: nil)
    Exec->>YAML: Process templates/functions (no auth)
    YAML-->>Exec: Results without credentials
    Exec-->>CLI: Component description
    end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~75 minutes

Areas requiring extra attention:

  • ExecuteDescribeComponentParams refactoring: This struct-based parameter change affects 40+ call sites across multiple packages (cmd, internal/exec, pkg). Verify all call sites are correctly updated and pass all parameters.
  • AuthManager propagation logic: Review the AuthContext population patterns in describe_stacks.go (Terraform/Helmfile/Packer processing) and describe_component.go to ensure consistent handling of nil AuthManager and AuthContext edge cases.
  • NewAuthManager signature change: The addition of *schema.ConfigAndStacksInfo parameter affects auth initialization across multiple describe commands; verify error handling and stack info population are correct.
  • authContextWrapper implementation: This internal wrapper in terraform_output_utils.go is a novel pattern for propagating auth context through YAML functions; ensure panic stubs for unused methods won't cause issues in edge cases.
  • Test coverage for nil scenarios: Multiple new test files cover AuthManager nil handling; verify they don't mask real issues and that backward compatibility is maintained.

Possibly related PRs

Suggested reviewers

  • osterman

Pre-merge checks and finishing touches

✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The pull request title "Fix authentication in YAML template functions and add --identity flag to describe commands" directly and clearly summarizes the two primary changes in this changeset. It addresses both the critical bug fix (authentication context not being threaded to YAML template functions) and the new feature (adding --identity flag to describe commands). The title is specific, concise (90 characters), and immediately communicates the most important aspects of the change without being vague or overly broad. A reviewer scanning the commit history would quickly understand the scope and intent of this PR.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix-auth-terraform-state

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 6

@codecov
Copy link

codecov bot commented Nov 3, 2025

Codecov Report

❌ Patch coverage is 76.26459% with 61 lines in your changes missing coverage. Please review.
✅ Project coverage is 69.11%. Comparing base (08cacb1) to head (a81e88a).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
cmd/identity_flag.go 23.80% 16 Missing ⚠️
internal/exec/atmos.go 0.00% 9 Missing ⚠️
cmd/cmd_utils.go 33.33% 8 Missing ⚠️
internal/exec/describe_stacks.go 38.46% 6 Missing and 2 partials ⚠️
cmd/describe_component.go 63.63% 2 Missing and 2 partials ⚠️
cmd/describe_affected.go 60.00% 1 Missing and 1 partial ⚠️
cmd/describe_dependents.go 60.00% 1 Missing and 1 partial ⚠️
cmd/describe_stacks.go 60.00% 1 Missing and 1 partial ⚠️
internal/exec/template_funcs_component.go 86.66% 1 Missing and 1 partial ⚠️
internal/exec/terraform_output_utils.go 97.33% 1 Missing and 1 partial ⚠️
... and 6 more
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1742      +/-   ##
==========================================
+ Coverage   69.06%   69.11%   +0.05%     
==========================================
  Files         388      388              
  Lines       35339    35554     +215     
==========================================
+ Hits        24406    24573     +167     
- Misses       8665     8705      +40     
- Partials     2268     2276       +8     
Flag Coverage Δ
unittests 69.11% <76.26%> (+0.05%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
cmd/describe.go 100.00% <100.00%> (ø)
cmd/list_stacks.go 50.00% <100.00%> (ø)
errors/errors.go 100.00% <ø> (ø)
internal/exec/describe_affected.go 66.66% <ø> (ø)
internal/exec/describe_affected_utils.go 78.86% <100.00%> (+4.48%) ⬆️
internal/exec/describe_dependents.go 79.00% <100.00%> (+0.31%) ⬆️
internal/exec/stacks_processor.go 100.00% <100.00%> (ø)
internal/exec/template_funcs.go 100.00% <100.00%> (ø)
internal/exec/terraform_clean.go 26.71% <100.00%> (ø)
internal/exec/terraform_query.go 74.19% <100.00%> (+0.86%) ⬆️
... and 23 more
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

aknysh and others added 2 commits November 2, 2025 22:03
… functions

Fixed critical nil pointer dereferences in terraform output YAML functions
(!terraform.output, !terraform.state) when auth context is nil. The issue
was caused by Go's interface nil gotcha where assigning a nil pointer to
an interface variable creates a non-nil interface.

## Changes

### Core Fixes
- internal/exec/terraform_output_utils.go:
  - Fixed authMgr declaration to use interface type with conditional assignment
  - Added auth package import
  - Added defer perf.Track() calls to all authContextWrapper methods

- internal/exec/template_funcs_component.go:
  - Applied same nil interface fix for authMgr variable
  - Added auth package import

### Code Review Fixes
- cmd/describe_component.go:
  - Simplified to use CreateAuthManagerFromIdentity helper
  - Removed duplicated auth manager creation logic
  - Removed unused imports (context, auth, credentials, validation)

- internal/exec/describe_dependents.go:
  - Thread AuthManager through ExecuteDescribeStacks call (line 148)
  - Thread AuthManager through ExecuteDescribeComponent call (line 160)

- internal/exec/describe_stacks_authmanager_propagation_test.go:
  - Changed .AnyTimes() to .Times(1) in mock expectations

### Test Coverage
- tests/cli_describe_identity_test.go (NEW):
  - CLI integration tests for describe commands with --identity flag
  - Verifies no interactive selector shown with explicit identity
  - Tests backward compatibility without --identity flag

- internal/exec/terraform_output_authcontext_wrapper_test.go (NEW):
  - Unit tests for authContextWrapper
  - Tests wrapper creation and GetStackInfo method
  - Verifies all stub methods panic as expected
  - Uses context.TODO() instead of nil per linter requirements

### Documentation
- website/blog/2025-11-02-describe-commands-identity-flag.mdx:
  - Fixed MDX syntax error: `<100ms` → backticks
  - Fixed broken links to /cli/commands/auth/usage
  - Fixed template functions links to /functions/yaml

- website/docs/cli/commands/describe/*.mdx (4 files):
  - Updated authentication links to correct URL

### Test Results
- ✅ terraform_output_function - PASSING
- ✅ terraform_output_function_(no_tty) - PASSING
- ✅ All AuthManager tests - PASSING
- ✅ All new CLI integration tests - PASSING
- ✅ Code compiles successfully
- ✅ Website builds successfully

Fixes #1742 (CodeRabbit review comments)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (3)
internal/exec/terraform_output_authcontext_wrapper_test.go (1)

57-170: Consider refactoring to a table-driven test.

This test validates that all stub methods panic, which is good defensive testing. However, the repetitive pattern across 17 sub-tests could be consolidated using a table-driven approach for better maintainability.

Here's how you could refactor this:

-	t.Run("GetCachedCredentials panics", func(t *testing.T) {
-		assert.Panics(t, func() {
-			_, _ = wrapper.GetCachedCredentials(context.TODO(), "test")
-		}, "GetCachedCredentials should panic")
-	})
-
-	t.Run("Authenticate panics", func(t *testing.T) {
-		assert.Panics(t, func() {
-			_, _ = wrapper.Authenticate(context.TODO(), "test")
-		}, "Authenticate should panic")
-	})
-
-	// ... (rest of the repetitive tests)
+	tests := []struct {
+		name string
+		fn   func()
+	}{
+		{"GetCachedCredentials", func() { _, _ = wrapper.GetCachedCredentials(context.TODO(), "test") }},
+		{"Authenticate", func() { _, _ = wrapper.Authenticate(context.TODO(), "test") }},
+		{"Whoami", func() { _, _ = wrapper.Whoami(context.TODO(), "test") }},
+		{"Validate", func() { _ = wrapper.Validate() }},
+		{"GetDefaultIdentity", func() { _, _ = wrapper.GetDefaultIdentity(false) }},
+		{"ListProviders", func() { _ = wrapper.ListProviders() }},
+		{"Logout", func() { _ = wrapper.Logout(context.TODO(), "test") }},
+		{"GetChain", func() { _ = wrapper.GetChain() }},
+		{"ListIdentities", func() { _ = wrapper.ListIdentities() }},
+		{"GetProviderForIdentity", func() { _ = wrapper.GetProviderForIdentity("test") }},
+		{"GetFilesDisplayPath", func() { _ = wrapper.GetFilesDisplayPath("test") }},
+		{"GetProviderKindForIdentity", func() { _, _ = wrapper.GetProviderKindForIdentity("test") }},
+		{"GetIdentities", func() { _ = wrapper.GetIdentities() }},
+		{"GetProviders", func() { _ = wrapper.GetProviders() }},
+		{"LogoutProvider", func() { _ = wrapper.LogoutProvider(context.TODO(), "test") }},
+		{"LogoutAll", func() { _ = wrapper.LogoutAll(context.TODO()) }},
+		{"GetEnvironmentVariables", func() { _, _ = wrapper.GetEnvironmentVariables("test") }},
+		{"PrepareShellEnvironment", func() { _, _ = wrapper.PrepareShellEnvironment(context.TODO(), "test", nil) }},
+	}
+
+	for _, tt := range tests {
+		t.Run(tt.name+" panics", func(t *testing.T) {
+			assert.Panics(t, tt.fn, tt.name+" should panic")
+		})
+	}

This approach makes it easier to add or remove methods and follows the table-driven test pattern recommended in the coding guidelines.

internal/exec/terraform_output_utils.go (1)

66-198: Consider returning errors instead of panicking in stub methods.

The authContextWrapper implements the AuthManager interface with most methods panicking. While this works for the current code path (as confirmed by testing), panics are fragile—if future changes inadvertently call any stub method, the process crashes at runtime instead of returning a graceful error.

Consider returning meaningful errors (e.g., errors.New("method not supported by authContextWrapper")) instead of panicking. This maintains the same contract while providing safer failure modes.

Apply this pattern to stub methods:

 func (a *authContextWrapper) GetCachedCredentials(ctx context.Context, identityName string) (*auth_types.WhoamiInfo, error) {
 	defer perf.Track(nil, "exec.authContextWrapper.GetCachedCredentials")()
 
-	panic("authContextWrapper.GetCachedCredentials should not be called")
+	return nil, errors.New("authContextWrapper does not support GetCachedCredentials")
 }
tests/cli_describe_identity_test.go (1)

107-143: LGTM!

These tests properly verify backward compatibility—commands work without the identity flag. Error assertions are correct.

Optional: The atmosRunner initialization (lines 109-114) is duplicated from the first test function. Consider extracting to a package-level TestMain or helper function if this pattern continues across more test files.

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between a2e959d and 31cb0aa.

📒 Files selected for processing (15)
  • cmd/describe_component.go (3 hunks)
  • internal/exec/describe_dependents.go (5 hunks)
  • internal/exec/describe_stacks_authmanager_propagation_test.go (1 hunks)
  • internal/exec/template_funcs.go (1 hunks)
  • internal/exec/template_funcs_component.go (4 hunks)
  • internal/exec/template_funcs_component_test.go (3 hunks)
  • internal/exec/terraform_output_authcontext_wrapper_test.go (1 hunks)
  • internal/exec/terraform_output_utils.go (3 hunks)
  • tests/cli_describe_identity_test.go (1 hunks)
  • tests/snapshots/TestCLICommands_atmos_auth_whoami_without_authentication.stderr.golden (1 hunks)
  • website/blog/2025-11-02-describe-commands-identity-flag.mdx (1 hunks)
  • website/docs/cli/commands/describe/describe-affected.mdx (3 hunks)
  • website/docs/cli/commands/describe/describe-component.mdx (3 hunks)
  • website/docs/cli/commands/describe/describe-dependents.mdx (3 hunks)
  • website/docs/cli/commands/describe/describe-stacks.mdx (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (5)
  • website/docs/cli/commands/describe/describe-affected.mdx
  • internal/exec/template_funcs_component.go
  • internal/exec/describe_stacks_authmanager_propagation_test.go
  • website/docs/cli/commands/describe/describe-dependents.mdx
  • website/docs/cli/commands/describe/describe-component.mdx
🧰 Additional context used
📓 Path-based instructions (5)
**/*_test.go

📄 CodeRabbit inference engine (.cursor/rules/atmos-rules.mdc)

**/*_test.go: Every new feature must include comprehensive unit tests
Test both happy paths and error conditions
Use table-driven tests for multiple scenarios

Files:

  • internal/exec/terraform_output_authcontext_wrapper_test.go
  • tests/cli_describe_identity_test.go
  • internal/exec/template_funcs_component_test.go
**/*.go

📄 CodeRabbit inference engine (.cursor/rules/atmos-rules.mdc)

**/*.go: All code must pass golangci-lint checks
Follow Go error handling idioms and use meaningful error messages
Wrap errors with context using fmt.Errorf("context: %w", err)
Consider custom error types for domain-specific errors
Follow standard Go coding style; run gofmt and goimports
Use snake_case for environment variables
Document complex logic with inline comments

Files:

  • internal/exec/terraform_output_authcontext_wrapper_test.go
  • tests/cli_describe_identity_test.go
  • cmd/describe_component.go
  • internal/exec/terraform_output_utils.go
  • internal/exec/template_funcs_component_test.go
  • internal/exec/describe_dependents.go
  • internal/exec/template_funcs.go
website/**

📄 CodeRabbit inference engine (.cursor/rules/atmos-rules.mdc)

website/**: Update website documentation in website/ when adding features
Ensure consistency between CLI help text and website documentation
Follow the website's documentation structure and style
Keep website code in website/ and follow its architecture/style; test changes locally
Keep CLI and website documentation in sync; document new features with examples and use cases

Files:

  • website/docs/cli/commands/describe/describe-stacks.mdx
  • website/blog/2025-11-02-describe-commands-identity-flag.mdx
cmd/**/*.go

📄 CodeRabbit inference engine (.cursor/rules/atmos-rules.mdc)

cmd/**/*.go: Use Cobra's recommended command structure with a root command and subcommands
Implement each CLI command in a separate file under cmd/
Use Viper for managing configuration, environment variables, and flags in the CLI
Keep separation of concerns between CLI interface (cmd) and business logic
Use kebab-case for command-line flags
Provide comprehensive help text for all commands and flags
Include examples in Cobra command help
Use Viper for configuration management; support files, env vars, and flags with precedence flags > env > config > defaults
Follow single responsibility; separate command interface from business logic
Provide meaningful user feedback and include progress indicators for long-running operations
Provide clear error messages to users and troubleshooting hints where appropriate

Files:

  • cmd/describe_component.go
**/!(*_test).go

📄 CodeRabbit inference engine (.cursor/rules/atmos-rules.mdc)

Document all exported functions, types, and methods with Go doc comments

Files:

  • cmd/describe_component.go
  • internal/exec/terraform_output_utils.go
  • internal/exec/describe_dependents.go
  • internal/exec/template_funcs.go
🧠 Learnings (49)
📓 Common learnings
Learnt from: Listener430
Repo: cloudposse/atmos PR: 934
File: tests/fixtures/scenarios/docs-generate/README.md.gotmpl:99-118
Timestamp: 2025-01-25T03:51:57.689Z
Learning: For the cloudposse/atmos repository, changes to template contents should be handled in dedicated PRs and are typically considered out of scope for PRs focused on other objectives.
Learnt from: Benbentwo
Repo: cloudposse/atmos PR: 1452
File: cmd/auth_login.go:43-44
Timestamp: 2025-09-07T18:07:00.549Z
Learning: In the atmos project, the identity flag is defined as a persistent flag on the auth root command (cmd/auth.go), making it available to all auth subcommands without needing to be redefined in each individual subcommand.
Learnt from: osterman
Repo: cloudposse/atmos PR: 1599
File: internal/exec/terraform.go:394-402
Timestamp: 2025-10-10T23:51:36.597Z
Learning: In Atmos (internal/exec/terraform.go), when adding OpenTofu-specific flags like `--var-file` for `init`, do not gate them based on command name (e.g., checking if `info.Command == "tofu"` or `info.Command == "opentofu"`) because command names don't reliably indicate the actual binary being executed (symlinks, aliases). Instead, document the OpenTofu requirement in code comments and documentation, trusting users who enable the feature (e.g., `PassVars`) to ensure their terraform command points to an OpenTofu binary.
Learnt from: aknysh
Repo: cloudposse/atmos PR: 1327
File: cmd/terraform.go:111-117
Timestamp: 2025-06-23T02:14:30.937Z
Learning: In cmd/terraform.go, flags for the DescribeAffected function are added dynamically at runtime when info.Affected is true. This is intentional to avoid exposing internal flags like "file", "format", "verbose", "include-spacelift-admin-stacks", "include-settings", and "upload" in the terraform command interface, while still providing them for the shared DescribeAffected function used by both `atmos describe affected` and `atmos terraform apply --affected`.
Learnt from: Benbentwo
Repo: cloudposse/atmos PR: 1475
File: pkg/auth/manager.go:304-312
Timestamp: 2025-09-25T01:02:48.697Z
Learning: The auth manager in pkg/auth/manager.go should remain cloud-agnostic and not contain AWS-specific logic or references to specific cloud providers. Keep the manager generic and extensible.
📚 Learning: 2024-12-07T16:19:01.683Z
Learnt from: aknysh
Repo: cloudposse/atmos PR: 825
File: internal/exec/terraform.go:30-30
Timestamp: 2024-12-07T16:19:01.683Z
Learning: In `internal/exec/terraform.go`, skipping stack validation when help flags are present is not necessary.

Applied to files:

  • internal/exec/terraform_output_authcontext_wrapper_test.go
📚 Learning: 2025-09-23T02:30:42.362Z
Learnt from: CR
Repo: cloudposse/atmos PR: 0
File: .cursor/rules/atmos-rules.mdc:0-0
Timestamp: 2025-09-23T02:30:42.362Z
Learning: Applies to **/*_test.go : Test both happy paths and error conditions

Applied to files:

  • internal/exec/terraform_output_authcontext_wrapper_test.go
  • tests/cli_describe_identity_test.go
📚 Learning: 2025-09-07T18:07:00.549Z
Learnt from: Benbentwo
Repo: cloudposse/atmos PR: 1452
File: cmd/auth_login.go:43-44
Timestamp: 2025-09-07T18:07:00.549Z
Learning: In the atmos project, the identity flag is defined as a persistent flag on the auth root command (cmd/auth.go), making it available to all auth subcommands without needing to be redefined in each individual subcommand.

Applied to files:

  • tests/cli_describe_identity_test.go
  • cmd/describe_component.go
  • internal/exec/terraform_output_utils.go
  • website/blog/2025-11-02-describe-commands-identity-flag.mdx
📚 Learning: 2025-09-23T02:30:42.362Z
Learnt from: CR
Repo: cloudposse/atmos PR: 0
File: .cursor/rules/atmos-rules.mdc:0-0
Timestamp: 2025-09-23T02:30:42.362Z
Learning: Applies to **/*_test.go : Every new feature must include comprehensive unit tests

Applied to files:

  • tests/cli_describe_identity_test.go
📚 Learning: 2025-06-23T02:14:30.937Z
Learnt from: aknysh
Repo: cloudposse/atmos PR: 1327
File: cmd/terraform.go:111-117
Timestamp: 2025-06-23T02:14:30.937Z
Learning: In cmd/terraform.go, flags for the DescribeAffected function are added dynamically at runtime when info.Affected is true. This is intentional to avoid exposing internal flags like "file", "format", "verbose", "include-spacelift-admin-stacks", "include-settings", and "upload" in the terraform command interface, while still providing them for the shared DescribeAffected function used by both `atmos describe affected` and `atmos terraform apply --affected`.

Applied to files:

  • tests/cli_describe_identity_test.go
  • website/docs/cli/commands/describe/describe-stacks.mdx
  • internal/exec/terraform_output_utils.go
  • website/blog/2025-11-02-describe-commands-identity-flag.mdx
📚 Learning: 2025-10-10T23:51:36.597Z
Learnt from: osterman
Repo: cloudposse/atmos PR: 1599
File: internal/exec/terraform.go:394-402
Timestamp: 2025-10-10T23:51:36.597Z
Learning: In Atmos (internal/exec/terraform.go), when adding OpenTofu-specific flags like `--var-file` for `init`, do not gate them based on command name (e.g., checking if `info.Command == "tofu"` or `info.Command == "opentofu"`) because command names don't reliably indicate the actual binary being executed (symlinks, aliases). Instead, document the OpenTofu requirement in code comments and documentation, trusting users who enable the feature (e.g., `PassVars`) to ensure their terraform command points to an OpenTofu binary.

Applied to files:

  • tests/cli_describe_identity_test.go
  • cmd/describe_component.go
  • internal/exec/terraform_output_utils.go
  • internal/exec/describe_dependents.go
  • website/blog/2025-11-02-describe-commands-identity-flag.mdx
📚 Learning: 2024-11-13T21:37:07.852Z
Learnt from: Cerebrovinny
Repo: cloudposse/atmos PR: 764
File: internal/exec/describe_stacks.go:289-295
Timestamp: 2024-11-13T21:37:07.852Z
Learning: In the `internal/exec/describe_stacks.go` file of the `atmos` project written in Go, avoid extracting the stack name handling logic into a helper function within the `ExecuteDescribeStacks` method, even if the logic appears duplicated.

Applied to files:

  • tests/cli_describe_identity_test.go
  • website/docs/cli/commands/describe/describe-stacks.mdx
  • cmd/describe_component.go
  • internal/exec/terraform_output_utils.go
  • internal/exec/describe_dependents.go
  • internal/exec/template_funcs.go
📚 Learning: 2025-05-23T19:51:47.091Z
Learnt from: samtholiya
Repo: cloudposse/atmos PR: 1255
File: cmd/describe_affected_test.go:15-15
Timestamp: 2025-05-23T19:51:47.091Z
Learning: The atmos codebase has a custom extension to *testing.T that provides a Chdir method, allowing test functions to call t.Chdir() to change working directories during tests. This is used consistently across test files in the codebase.

Applied to files:

  • tests/cli_describe_identity_test.go
📚 Learning: 2025-09-23T02:30:42.362Z
Learnt from: CR
Repo: cloudposse/atmos PR: 0
File: .cursor/rules/atmos-rules.mdc:0-0
Timestamp: 2025-09-23T02:30:42.362Z
Learning: Applies to **/*_test.go : Use table-driven tests for multiple scenarios

Applied to files:

  • tests/cli_describe_identity_test.go
📚 Learning: 2025-10-07T00:25:16.333Z
Learnt from: osterman
Repo: cloudposse/atmos PR: 1498
File: website/src/components/Screengrabs/atmos-terraform-metadata--help.html:25-55
Timestamp: 2025-10-07T00:25:16.333Z
Learning: In Atmos CLI, subcommands inherit flags from their parent commands via Cobra's command inheritance. For example, `atmos terraform metadata --help` shows `--affected` and related flags inherited from the parent `terraform` command (defined in cmd/terraform.go), even though the metadata subcommand doesn't explicitly define these flags. This is expected Cobra behavior and auto-generated help screengrabs accurately reflect this inheritance.

Applied to files:

  • tests/cli_describe_identity_test.go
  • website/docs/cli/commands/describe/describe-stacks.mdx
  • website/blog/2025-11-02-describe-commands-identity-flag.mdx
📚 Learning: 2025-01-09T22:27:25.538Z
Learnt from: samtholiya
Repo: cloudposse/atmos PR: 914
File: cmd/validate_stacks.go:20-23
Timestamp: 2025-01-09T22:27:25.538Z
Learning: The validate commands in Atmos can have different help handling implementations. Specifically, validate_component.go and validate_stacks.go are designed to handle help requests differently, with validate_stacks.go including positional argument checks while validate_component.go does not.

Applied to files:

  • tests/cli_describe_identity_test.go
  • website/docs/cli/commands/describe/describe-stacks.mdx
  • cmd/describe_component.go
📚 Learning: 2024-12-01T00:33:20.298Z
Learnt from: aknysh
Repo: cloudposse/atmos PR: 810
File: examples/tests/stacks/catalog/terraform/template-functions-test2/defaults.yaml:28-32
Timestamp: 2024-12-01T00:33:20.298Z
Learning: In `examples/tests/stacks/catalog/terraform/template-functions-test2/defaults.yaml`, `!exec atmos terraform output` is used in examples to demonstrate its usage, even though `!terraform.output` is the recommended approach according to the documentation.

Applied to files:

  • website/docs/cli/commands/describe/describe-stacks.mdx
📚 Learning: 2025-01-19T15:49:15.593Z
Learnt from: samtholiya
Repo: cloudposse/atmos PR: 955
File: tests/snapshots/TestCLICommands_atmos_validate_editorconfig_--help.stdout.golden:0-0
Timestamp: 2025-01-19T15:49:15.593Z
Learning: In future commits, the help text for Atmos CLI commands should be limited to only show component and stack parameters for commands that actually use them. This applies to the example usage section in command help text.

Applied to files:

  • website/docs/cli/commands/describe/describe-stacks.mdx
📚 Learning: 2025-01-19T22:30:27.600Z
Learnt from: aknysh
Repo: cloudposse/atmos PR: 0
File: :0-0
Timestamp: 2025-01-19T22:30:27.600Z
Learning: The Atmos YAML function `!env` is used to retrieve environment variables and assign them to sections in stack manifests. It supports both simple types (string, number, boolean) and complex types (JSON-encoded lists, maps, objects).

Applied to files:

  • website/docs/cli/commands/describe/describe-stacks.mdx
📚 Learning: 2025-01-19T22:30:27.600Z
Learnt from: aknysh
Repo: cloudposse/atmos PR: 0
File: :0-0
Timestamp: 2025-01-19T22:30:27.600Z
Learning: The Atmos YAML function `!include` allows downloading local or remote files from different sources and assigning their contents to sections in stack manifests. It supports various protocols (file, http, git, s3, etc.) and can filter content using YQ expressions.

Applied to files:

  • website/docs/cli/commands/describe/describe-stacks.mdx
📚 Learning: 2025-09-13T16:39:20.007Z
Learnt from: samtholiya
Repo: cloudposse/atmos PR: 1466
File: cmd/markdown/atmos_toolchain_aliases.md:2-4
Timestamp: 2025-09-13T16:39:20.007Z
Learning: In the cloudposse/atmos repository, CLI documentation files in cmd/markdown/ follow a specific format that uses " $ atmos command" (with leading space and dollar sign prompt) in code blocks. This is the established project convention and should not be changed to comply with standard markdownlint rules MD040 and MD014.

Applied to files:

  • website/docs/cli/commands/describe/describe-stacks.mdx
  • tests/snapshots/TestCLICommands_atmos_auth_whoami_without_authentication.stderr.golden
📚 Learning: 2024-12-03T05:18:49.169Z
Learnt from: aknysh
Repo: cloudposse/atmos PR: 810
File: internal/exec/terraform_utils.go:40-213
Timestamp: 2024-12-03T05:18:49.169Z
Learning: In the context of the Atmos project, it's acceptable for functions like `execTerraformOutput` to remain as single functions if they perform a single purpose, such as retrieving Terraform outputs for a component in a stack, even if the function is lengthy.

Applied to files:

  • website/docs/cli/commands/describe/describe-stacks.mdx
  • internal/exec/terraform_output_utils.go
📚 Learning: 2025-09-25T01:02:48.697Z
Learnt from: Benbentwo
Repo: cloudposse/atmos PR: 1475
File: pkg/auth/manager.go:304-312
Timestamp: 2025-09-25T01:02:48.697Z
Learning: The auth manager in pkg/auth/manager.go should remain cloud-agnostic and not contain AWS-specific logic or references to specific cloud providers. Keep the manager generic and extensible.

Applied to files:

  • cmd/describe_component.go
  • internal/exec/terraform_output_utils.go
  • internal/exec/describe_dependents.go
📚 Learning: 2025-08-16T23:32:40.412Z
Learnt from: aknysh
Repo: cloudposse/atmos PR: 1405
File: internal/exec/describe_dependents_test.go:455-456
Timestamp: 2025-08-16T23:32:40.412Z
Learning: In the cloudposse/atmos Go codebase, `InitCliConfig` returns a `schema.AtmosConfiguration` value (not a pointer), while `ExecuteDescribeDependents` expects a `*schema.AtmosConfiguration` pointer parameter. Therefore, when passing the result of `InitCliConfig` to `ExecuteDescribeDependents`, use `&atmosConfig` to pass the address of the value.

Applied to files:

  • cmd/describe_component.go
  • internal/exec/terraform_output_utils.go
  • internal/exec/template_funcs_component_test.go
  • internal/exec/describe_dependents.go
  • internal/exec/template_funcs.go
📚 Learning: 2024-10-23T21:36:40.262Z
Learnt from: osterman
Repo: cloudposse/atmos PR: 740
File: cmd/cmd_utils.go:340-359
Timestamp: 2024-10-23T21:36:40.262Z
Learning: In the Go codebase for Atmos, when reviewing functions like `checkAtmosConfig` in `cmd/cmd_utils.go`, avoid suggesting refactoring to return errors instead of calling `os.Exit` if such changes would significantly increase the scope due to the need to update multiple call sites.

Applied to files:

  • cmd/describe_component.go
  • internal/exec/terraform_output_utils.go
  • internal/exec/template_funcs_component_test.go
  • internal/exec/describe_dependents.go
  • internal/exec/template_funcs.go
📚 Learning: 2024-12-02T21:26:32.337Z
Learnt from: osterman
Repo: cloudposse/atmos PR: 808
File: pkg/config/config.go:478-483
Timestamp: 2024-12-02T21:26:32.337Z
Learning: In the 'atmos' project, when reviewing Go code like `pkg/config/config.go`, avoid suggesting file size checks after downloading remote configs if such checks aren't implemented elsewhere in the codebase.

Applied to files:

  • cmd/describe_component.go
  • internal/exec/template_funcs_component_test.go
📚 Learning: 2025-08-16T23:33:07.477Z
Learnt from: aknysh
Repo: cloudposse/atmos PR: 1405
File: internal/exec/describe_dependents_test.go:651-652
Timestamp: 2025-08-16T23:33:07.477Z
Learning: In the cloudposse/atmos Go codebase, ExecuteDescribeDependents expects a pointer to AtmosConfiguration (*schema.AtmosConfiguration), so when calling it with a value returned by cfg.InitCliConfig (which returns schema.AtmosConfiguration), the address-of operator (&) is necessary: ExecuteDescribeDependents(&atmosConfig, ...).

Applied to files:

  • cmd/describe_component.go
  • internal/exec/terraform_output_utils.go
  • internal/exec/template_funcs_component_test.go
  • internal/exec/describe_dependents.go
  • internal/exec/template_funcs.go
📚 Learning: 2025-09-23T02:30:42.362Z
Learnt from: CR
Repo: cloudposse/atmos PR: 0
File: .cursor/rules/atmos-rules.mdc:0-0
Timestamp: 2025-09-23T02:30:42.362Z
Learning: Applies to cmd/**/*.go : Use Cobra's recommended command structure with a root command and subcommands

Applied to files:

  • cmd/describe_component.go
📚 Learning: 2025-09-23T02:30:42.362Z
Learnt from: CR
Repo: cloudposse/atmos PR: 0
File: .cursor/rules/atmos-rules.mdc:0-0
Timestamp: 2025-09-23T02:30:42.362Z
Learning: Applies to cmd/**/*.go : Provide comprehensive help text for all commands and flags

Applied to files:

  • cmd/describe_component.go
📚 Learning: 2025-09-23T02:30:42.362Z
Learnt from: CR
Repo: cloudposse/atmos PR: 0
File: .cursor/rules/atmos-rules.mdc:0-0
Timestamp: 2025-09-23T02:30:42.362Z
Learning: Applies to cmd/**/*.go : Provide clear error messages to users and troubleshooting hints where appropriate

Applied to files:

  • cmd/describe_component.go
📚 Learning: 2025-09-23T02:30:42.362Z
Learnt from: CR
Repo: cloudposse/atmos PR: 0
File: .cursor/rules/atmos-rules.mdc:0-0
Timestamp: 2025-09-23T02:30:42.362Z
Learning: Applies to cmd/**/*.go : Include examples in Cobra command help

Applied to files:

  • cmd/describe_component.go
📚 Learning: 2025-09-23T02:30:42.362Z
Learnt from: CR
Repo: cloudposse/atmos PR: 0
File: .cursor/rules/atmos-rules.mdc:0-0
Timestamp: 2025-09-23T02:30:42.362Z
Learning: Applies to cmd/**/*.go : Use Viper for managing configuration, environment variables, and flags in the CLI

Applied to files:

  • cmd/describe_component.go
📚 Learning: 2024-12-11T18:40:12.808Z
Learnt from: Listener430
Repo: cloudposse/atmos PR: 844
File: cmd/helmfile.go:37-37
Timestamp: 2024-12-11T18:40:12.808Z
Learning: In the atmos project, `cliConfig` is initialized within the `cmd` package in `root.go` and can be used in other command files.

Applied to files:

  • cmd/describe_component.go
  • internal/exec/terraform_output_utils.go
  • internal/exec/describe_dependents.go
📚 Learning: 2025-03-18T12:26:25.329Z
Learnt from: Listener430
Repo: cloudposse/atmos PR: 1149
File: tests/snapshots/TestCLICommands_atmos_vendor_pull_ssh.stderr.golden:7-7
Timestamp: 2025-03-18T12:26:25.329Z
Learning: In the Atmos project, typos or inconsistencies in test snapshot files (such as "terrafrom" instead of "terraform") may be intentional as they capture the exact output of commands and should not be flagged as issues requiring correction.

Applied to files:

  • tests/snapshots/TestCLICommands_atmos_auth_whoami_without_authentication.stderr.golden
📚 Learning: 2025-02-14T23:12:38.030Z
Learnt from: Listener430
Repo: cloudposse/atmos PR: 1061
File: tests/snapshots/TestCLICommands_atmos_vendor_pull_ssh.stderr.golden:8-8
Timestamp: 2025-02-14T23:12:38.030Z
Learning: Test snapshots in the Atmos project, particularly for dry run scenarios, may be updated during the development process, and temporary inconsistencies in their content should not be flagged as issues.

Applied to files:

  • tests/snapshots/TestCLICommands_atmos_auth_whoami_without_authentication.stderr.golden
📚 Learning: 2025-09-29T02:20:11.636Z
Learnt from: aknysh
Repo: cloudposse/atmos PR: 1540
File: internal/exec/validate_component.go:117-118
Timestamp: 2025-09-29T02:20:11.636Z
Learning: The ValidateComponent function in internal/exec/validate_component.go had its componentSection parameter type refined from `any` to `map[string]any` without adding new parameters. This is a type safety improvement, not a signature change requiring call site updates.

Applied to files:

  • internal/exec/terraform_output_utils.go
  • internal/exec/template_funcs_component_test.go
  • internal/exec/template_funcs.go
📚 Learning: 2025-10-03T18:02:08.535Z
Learnt from: Benbentwo
Repo: cloudposse/atmos PR: 1475
File: internal/exec/terraform.go:269-272
Timestamp: 2025-10-03T18:02:08.535Z
Learning: In internal/exec/terraform.go, when auth.TerraformPreHook fails, the error is logged but execution continues. This is a deliberate design choice to allow Terraform commands to proceed even if authentication setup fails, rather than failing fast.

Applied to files:

  • internal/exec/terraform_output_utils.go
📚 Learning: 2024-12-03T03:52:02.524Z
Learnt from: aknysh
Repo: cloudposse/atmos PR: 810
File: internal/exec/terraform_utils.go:144-145
Timestamp: 2024-12-03T03:52:02.524Z
Learning: Avoid adding context timeouts to Terraform commands in `execTerraformOutput` because their execution time can vary from seconds to hours, and making it configurable would require redesigning the command interface.

Applied to files:

  • internal/exec/terraform_output_utils.go
📚 Learning: 2025-07-05T20:59:02.914Z
Learnt from: aknysh
Repo: cloudposse/atmos PR: 1363
File: internal/exec/template_utils.go:18-18
Timestamp: 2025-07-05T20:59:02.914Z
Learning: In the Atmos project, gomplate v4 is imported with a blank import (`_ "github.com/hairyhenderson/gomplate/v4"`) alongside v3 imports to resolve AWS SDK version conflicts. V3 uses older AWS SDK versions that conflict with newer AWS modules used by Atmos. A full migration to v4 requires extensive refactoring due to API changes and should be handled in a separate PR.

Applied to files:

  • internal/exec/terraform_output_utils.go
  • internal/exec/template_funcs_component_test.go
  • internal/exec/describe_dependents.go
📚 Learning: 2025-09-13T18:06:07.674Z
Learnt from: samtholiya
Repo: cloudposse/atmos PR: 1466
File: toolchain/list.go:39-42
Timestamp: 2025-09-13T18:06:07.674Z
Learning: In the cloudposse/atmos repository, for UI messages in the toolchain package, use utils.PrintfMessageToTUI instead of log.Error or fmt.Fprintln(os.Stderr, ...). Import pkg/utils with alias "u" to follow the established pattern.

Applied to files:

  • internal/exec/terraform_output_utils.go
  • internal/exec/describe_dependents.go
📚 Learning: 2024-10-28T01:51:30.811Z
Learnt from: osterman
Repo: cloudposse/atmos PR: 727
File: internal/exec/terraform_clean.go:329-332
Timestamp: 2024-10-28T01:51:30.811Z
Learning: In the Atmos Go code, when deleting directories or handling file paths (e.g., in `terraform_clean.go`), always resolve the absolute path using `filepath.Abs` and use the logger `u.LogWarning` for logging messages instead of using `fmt.Printf`.

Applied to files:

  • internal/exec/terraform_output_utils.go
📚 Learning: 2025-02-06T13:38:07.216Z
Learnt from: Listener430
Repo: cloudposse/atmos PR: 984
File: internal/exec/copy_glob.go:0-0
Timestamp: 2025-02-06T13:38:07.216Z
Learning: The `u.LogTrace` function in the `cloudposse/atmos` repository accepts `atmosConfig` as its first parameter, followed by the message string.

Applied to files:

  • internal/exec/terraform_output_utils.go
  • internal/exec/describe_dependents.go
📚 Learning: 2024-12-03T05:29:07.718Z
Learnt from: aknysh
Repo: cloudposse/atmos PR: 810
File: internal/exec/terraform_utils.go:145-146
Timestamp: 2024-12-03T05:29:07.718Z
Learning: In the Atmos project, a 5-minute timeout in the `execTerraformOutput` function is acceptable for retrieving `terraform output` for a component in a stack.

Applied to files:

  • internal/exec/terraform_output_utils.go
📚 Learning: 2024-11-12T03:16:02.910Z
Learnt from: aknysh
Repo: cloudposse/atmos PR: 775
File: internal/exec/template_funcs_component.go:157-159
Timestamp: 2024-11-12T03:16:02.910Z
Learning: In the Go code for `componentFunc` in `internal/exec/template_funcs_component.go`, the function `cleanTerraformWorkspace` does not return errors, and it's acceptable if the file does not exist. Therefore, error handling for `cleanTerraformWorkspace` is not needed.

Applied to files:

  • internal/exec/template_funcs_component_test.go
  • internal/exec/template_funcs.go
📚 Learning: 2024-12-07T16:16:13.038Z
Learnt from: Listener430
Repo: cloudposse/atmos PR: 825
File: internal/exec/helmfile_generate_varfile.go:28-31
Timestamp: 2024-12-07T16:16:13.038Z
Learning: In `internal/exec/helmfile_generate_varfile.go`, the `--help` command (`./atmos helmfile generate varfile --help`) works correctly without requiring stack configurations, and the only change needed was to make `ProcessCommandLineArgs` exportable by capitalizing its name.

Applied to files:

  • internal/exec/template_funcs_component_test.go
  • internal/exec/template_funcs.go
📚 Learning: 2024-10-20T13:12:46.499Z
Learnt from: haitham911
Repo: cloudposse/atmos PR: 736
File: pkg/config/const.go:6-6
Timestamp: 2024-10-20T13:12:46.499Z
Learning: In `cmd/cmd_utils.go`, it's acceptable to have hardcoded references to `atmos.yaml` in logs, and it's not necessary to update them to use the `CliConfigFileName` constant.

Applied to files:

  • internal/exec/template_funcs_component_test.go
  • internal/exec/describe_dependents.go
📚 Learning: 2025-08-15T14:43:41.030Z
Learnt from: aknysh
Repo: cloudposse/atmos PR: 1352
File: pkg/store/artifactory_store_test.go:108-113
Timestamp: 2025-08-15T14:43:41.030Z
Learning: In test files for the atmos project, it's acceptable to ignore errors from os.Setenv/Unsetenv operations during test environment setup and teardown, as these are controlled test scenarios.

Applied to files:

  • internal/exec/template_funcs_component_test.go
📚 Learning: 2024-12-12T15:17:45.245Z
Learnt from: osterman
Repo: cloudposse/atmos PR: 808
File: examples/demo-atmos.d/atmos.d/tools/helmfile.yml:10-10
Timestamp: 2024-12-12T15:17:45.245Z
Learning: In `examples/demo-atmos.d/atmos.d/tools/helmfile.yml`, when suggesting changes to `kubeconfig_path`, ensure that the values use valid Go template syntax.

Applied to files:

  • internal/exec/template_funcs_component_test.go
📚 Learning: 2025-10-22T14:55:44.014Z
Learnt from: osterman
Repo: cloudposse/atmos PR: 1695
File: pkg/auth/manager.go:169-171
Timestamp: 2025-10-22T14:55:44.014Z
Learning: Go 1.20+ supports multiple %w verbs in fmt.Errorf, which returns an error implementing Unwrap() []error. This is valid and does not panic. Atmos uses Go 1.24.8 and configures errorlint with errorf-multi: true to validate this pattern.

Applied to files:

  • internal/exec/describe_dependents.go
📚 Learning: 2025-01-30T19:30:59.120Z
Learnt from: samtholiya
Repo: cloudposse/atmos PR: 959
File: cmd/workflow.go:74-74
Timestamp: 2025-01-30T19:30:59.120Z
Learning: Error handling for `cmd.Usage()` is not required in the Atmos CLI codebase, as confirmed by the maintainer.

Applied to files:

  • internal/exec/describe_dependents.go
📚 Learning: 2024-12-05T22:33:40.955Z
Learnt from: aknysh
Repo: cloudposse/atmos PR: 820
File: cmd/list_components.go:53-54
Timestamp: 2024-12-05T22:33:40.955Z
Learning: In the Atmos CLI Go codebase, using `u.LogErrorAndExit` within completion functions is acceptable because it logs the error and exits the command execution.

Applied to files:

  • internal/exec/describe_dependents.go
📚 Learning: 2025-08-29T20:57:35.423Z
Learnt from: osterman
Repo: cloudposse/atmos PR: 1433
File: cmd/theme_list.go:33-36
Timestamp: 2025-08-29T20:57:35.423Z
Learning: In the Atmos codebase, avoid using viper.SetEnvPrefix("ATMOS") with viper.AutomaticEnv() because canonical environment variable names are not exclusive to Atmos and could cause conflicts. Instead, use selective environment variable binding through the setEnv function in pkg/config/load.go with bindEnv(v, "config.key", "ENV_VAR_NAME") for specific environment variables.

Applied to files:

  • internal/exec/describe_dependents.go
📚 Learning: 2025-09-05T14:57:37.360Z
Learnt from: RoseSecurity
Repo: cloudposse/atmos PR: 1448
File: cmd/ansible.go:26-28
Timestamp: 2025-09-05T14:57:37.360Z
Learning: The Atmos codebase uses a consistent pattern for commands that delegate to external tools: `PersistentFlags().Bool("", false, doubleDashHint)` where doubleDashHint provides help text about using double dashes to separate Atmos options from native command arguments. This pattern is used across terraform, packer, helmfile, atlantis, aws, and ansible commands.

Applied to files:

  • website/blog/2025-11-02-describe-commands-identity-flag.mdx
🧬 Code graph analysis (5)
internal/exec/terraform_output_authcontext_wrapper_test.go (1)
pkg/schema/schema.go (2)
  • AuthContext (498-506)
  • AWSAuthContext (510-525)
tests/cli_describe_identity_test.go (2)
tests/testhelpers/atmos_runner.go (1)
  • NewAtmosRunner (31-35)
pkg/logger/log.go (1)
  • Info (34-36)
cmd/describe_component.go (4)
pkg/config/config.go (1)
  • InitCliConfig (25-62)
pkg/schema/schema.go (1)
  • ConfigAndStacksInfo (527-610)
errors/errors.go (1)
  • ErrFailedToInitConfig (285-285)
cmd/identity_flag.go (2)
  • GetIdentityFromFlags (38-61)
  • CreateAuthManagerFromIdentity (115-156)
internal/exec/terraform_output_utils.go (3)
pkg/schema/schema.go (3)
  • ConfigAndStacksInfo (527-610)
  • Context (409-424)
  • AuthContext (498-506)
internal/exec/describe_component.go (2)
  • ExecuteDescribeComponent (212-228)
  • ExecuteDescribeComponentParams (202-209)
pkg/describe/describe_component.go (1)
  • ExecuteDescribeComponent (9-26)
internal/exec/describe_dependents.go (2)
internal/exec/describe_component.go (2)
  • ExecuteDescribeComponent (212-228)
  • ExecuteDescribeComponentParams (202-209)
pkg/describe/describe_component.go (1)
  • ExecuteDescribeComponent (9-26)
🪛 LanguageTool
website/blog/2025-11-02-describe-commands-identity-flag.mdx

[grammar] ~233-~233: Please add a punctuation mark at the end of paragraph.
Context: ... describe operations with authenticated access ### CI/CD Considerations **For CI/CD ...

(PUNCTUATION_PARAGRAPH_END)


[style] ~273-~273: Using many exclamation marks might seem excessive (in this case: 9 exclamation marks for a text that’s 5718 characters long)
Context: ...entials from context This ensures that !terraform.state and !terraform.output functions can access r...

(EN_EXCESSIVE_EXCLAMATION)

⏰ 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). (7)
  • GitHub Check: Build (windows)
  • GitHub Check: Build (linux)
  • GitHub Check: Review Dependency Licenses
  • GitHub Check: autofix
  • GitHub Check: website-deploy-preview
  • GitHub Check: Analyze (go)
  • GitHub Check: Summary
🔇 Additional comments (16)
tests/snapshots/TestCLICommands_atmos_auth_whoami_without_authentication.stderr.golden (1)

10-10: Skip commenting on trailing whitespace.

This is a single trailing space difference in a test snapshot, likely an artifact of regenerating the snapshot during authentication flow testing. No functional impact.

internal/exec/terraform_output_authcontext_wrapper_test.go (3)

1-11: Imports and package declaration look good.

Standard test setup with appropriate dependencies.


13-34: Test coverage for wrapper creation is solid.

Both nil and valid cases are tested appropriately.


36-55: GetStackInfo test validates proper context propagation.

Field-level checks ensure the authContext is correctly accessible.

website/docs/cli/commands/describe/describe-stacks.mdx (3)

27-29: Clear guidance on authentication requirements.

The info box effectively communicates when --identity is needed and how to disable function processing. This helps users understand the default behavior and available options.


57-61: Examples cover both authentication modes.

Good inclusion of both interactive and explicit identity usage patterns. The examples demonstrate real-world usage scenarios effectively.


100-101: Comprehensive flag documentation.

The --identity flag documentation clearly explains when it's required, provides both usage modes, and links to detailed auth docs. Well done.

website/blog/2025-11-02-describe-commands-identity-flag.mdx (1)

1-306: Comprehensive feature announcement.

This blog post effectively communicates the new feature with clear problem statement, solution explanation, practical examples, and migration guidance. The technical details section provides helpful context on implementation and performance characteristics. The backward compatibility emphasis and error handling explanations are particularly valuable for users.

internal/exec/describe_dependents.go (2)

31-31: AuthManager properly integrated into the flow.

The AuthManager field additions to both structs and the forwarding at line 92 correctly thread authentication through the describe dependents pipeline. Clean implementation.

Also applies to: 43-43, 92-92


148-161: Past review concern fully resolved.

Both call sites now correctly pass args.AuthManager instead of nil. The ExecuteDescribeStacks call at line 148 and the ExecuteDescribeComponent parameter struct at line 160 properly propagate the AuthManager, ensuring YAML template functions have access to authenticated credentials.

cmd/describe_component.go (1)

74-100: Auth flow properly centralized.

The code now uses CreateAuthManagerFromIdentity to handle identity→AuthManager setup, ensuring consistent validation across describe commands. The AuthManager is correctly threaded through to ExecuteDescribeComponent via the params struct, enabling authenticated credential access for YAML template functions like !terraform.state and !terraform.output.

internal/exec/template_funcs_component_test.go (1)

59-81: Test signatures correctly updated.

The test calls now include the additional configAndStacksInfo parameter (passed as nil), matching the updated componentFunc signature. This aligns with the broader auth context propagation refactor while keeping tests focused on their specific scenarios.

internal/exec/template_funcs.go (1)

46-46: Context propagation established.

The configAndStacksInfo is now threaded through to componentFunc, enabling downstream component resolution to access authentication context when template functions are evaluated.

internal/exec/terraform_output_utils.go (1)

550-564: Auth context propagation fixed.

The code now creates an authContextWrapper from authContext when available and passes it to ExecuteDescribeComponent, resolving the critical bug where YAML template functions couldn't access authenticated credentials. This directly addresses the past review concern about passing nil AuthManager.

tests/cli_describe_identity_test.go (2)

16-22: LGTM!

The atmosRunner initialization is properly handled with graceful skip on build failure and clear logging.


92-104: LGTM!

This test properly verifies the command succeeds without the identity flag and correctly asserts the expected behavior.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (2)
tests/cli_describe_identity_test.go (2)

15-22: Consider extracting duplicate atmosRunner initialization.

Both test functions have identical atmosRunner initialization logic. Extract to a helper function or use TestMain to reduce duplication:

func ensureAtmosRunner(t *testing.T) {
	if atmosRunner == nil {
		atmosRunner = testhelpers.NewAtmosRunner(coverDir)
		if err := atmosRunner.Build(); err != nil {
			t.Skipf("Failed to initialize Atmos: %v", err)
		}
		logger.Info("Atmos runner initialized", "coverageEnabled", coverDir != "")
	}
}

Then call ensureAtmosRunner(t) at the start of each test function.

Also applies to: 85-90


92-118: Consider table-driven tests for consistency.

These two tests follow the same pattern and could be combined using a table-driven approach, matching the style used in the first test function:

func TestDescribeCommandsWithoutAuthWork(t *testing.T) {
	ensureAtmosRunner(t)
	
	tests := []struct {
		name string
		args []string
	}{
		{
			name: "describe stacks without auth should work",
			args: []string{"describe", "stacks"},
		},
		{
			name: "list components without auth should work",
			args: []string{"list", "components"},
		},
	}
	
	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			t.Chdir("fixtures/scenarios/basic")
			
			cmd := atmosRunner.Command(tt.args...)
			
			var stdout, stderr bytes.Buffer
			cmd.Stdout = &stdout
			cmd.Stderr = &stderr
			err := cmd.Run()
			
			assert.NoError(t, err, tt.name)
		})
	}
}
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 31cb0aa and a81e88a.

📒 Files selected for processing (2)
  • tests/cli_describe_identity_test.go (1 hunks)
  • tests/fixtures/scenarios/authmanager-propagation/stacks/test.yaml (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • tests/fixtures/scenarios/authmanager-propagation/stacks/test.yaml
🧰 Additional context used
📓 Path-based instructions (2)
**/*_test.go

📄 CodeRabbit inference engine (.cursor/rules/atmos-rules.mdc)

**/*_test.go: Every new feature must include comprehensive unit tests
Test both happy paths and error conditions
Use table-driven tests for multiple scenarios

Files:

  • tests/cli_describe_identity_test.go
**/*.go

📄 CodeRabbit inference engine (.cursor/rules/atmos-rules.mdc)

**/*.go: All code must pass golangci-lint checks
Follow Go error handling idioms and use meaningful error messages
Wrap errors with context using fmt.Errorf("context: %w", err)
Consider custom error types for domain-specific errors
Follow standard Go coding style; run gofmt and goimports
Use snake_case for environment variables
Document complex logic with inline comments

Files:

  • tests/cli_describe_identity_test.go
🧠 Learnings (15)
📓 Common learnings
Learnt from: Listener430
Repo: cloudposse/atmos PR: 934
File: tests/fixtures/scenarios/docs-generate/README.md.gotmpl:99-118
Timestamp: 2025-01-25T03:51:57.689Z
Learning: For the cloudposse/atmos repository, changes to template contents should be handled in dedicated PRs and are typically considered out of scope for PRs focused on other objectives.
Learnt from: Benbentwo
Repo: cloudposse/atmos PR: 1452
File: cmd/auth_login.go:43-44
Timestamp: 2025-09-07T18:07:00.549Z
Learning: In the atmos project, the identity flag is defined as a persistent flag on the auth root command (cmd/auth.go), making it available to all auth subcommands without needing to be redefined in each individual subcommand.
Learnt from: aknysh
Repo: cloudposse/atmos PR: 944
File: go.mod:206-206
Timestamp: 2025-01-17T00:18:57.769Z
Learning: For indirect dependencies with license compliance issues in the cloudposse/atmos repository, the team prefers to handle them in follow-up PRs rather than blocking the current changes, as these issues often require deeper investigation of the dependency tree.
Learnt from: aknysh
Repo: cloudposse/atmos PR: 1327
File: cmd/terraform.go:111-117
Timestamp: 2025-06-23T02:14:30.937Z
Learning: In cmd/terraform.go, flags for the DescribeAffected function are added dynamically at runtime when info.Affected is true. This is intentional to avoid exposing internal flags like "file", "format", "verbose", "include-spacelift-admin-stacks", "include-settings", and "upload" in the terraform command interface, while still providing them for the shared DescribeAffected function used by both `atmos describe affected` and `atmos terraform apply --affected`.
Learnt from: osterman
Repo: cloudposse/atmos PR: 1498
File: website/src/components/Screengrabs/atmos-terraform-metadata--help.html:25-55
Timestamp: 2025-10-07T00:25:16.333Z
Learning: In Atmos CLI, subcommands inherit flags from their parent commands via Cobra's command inheritance. For example, `atmos terraform metadata --help` shows `--affected` and related flags inherited from the parent `terraform` command (defined in cmd/terraform.go), even though the metadata subcommand doesn't explicitly define these flags. This is expected Cobra behavior and auto-generated help screengrabs accurately reflect this inheritance.
Learnt from: RoseSecurity
Repo: cloudposse/atmos PR: 1448
File: cmd/ansible.go:26-28
Timestamp: 2025-09-05T14:57:37.360Z
Learning: The Atmos codebase uses a consistent pattern for commands that delegate to external tools: `PersistentFlags().Bool("", false, doubleDashHint)` where doubleDashHint provides help text about using double dashes to separate Atmos options from native command arguments. This pattern is used across terraform, packer, helmfile, atlantis, aws, and ansible commands.
Learnt from: osterman
Repo: cloudposse/atmos PR: 1599
File: internal/exec/terraform.go:394-402
Timestamp: 2025-10-10T23:51:36.597Z
Learning: In Atmos (internal/exec/terraform.go), when adding OpenTofu-specific flags like `--var-file` for `init`, do not gate them based on command name (e.g., checking if `info.Command == "tofu"` or `info.Command == "opentofu"`) because command names don't reliably indicate the actual binary being executed (symlinks, aliases). Instead, document the OpenTofu requirement in code comments and documentation, trusting users who enable the feature (e.g., `PassVars`) to ensure their terraform command points to an OpenTofu binary.
Learnt from: aknysh
Repo: cloudposse/atmos PR: 1405
File: internal/exec/describe_dependents_test.go:455-456
Timestamp: 2025-08-16T23:32:40.412Z
Learning: In the cloudposse/atmos Go codebase, `InitCliConfig` returns a `schema.AtmosConfiguration` value (not a pointer), while `ExecuteDescribeDependents` expects a `*schema.AtmosConfiguration` pointer parameter. Therefore, when passing the result of `InitCliConfig` to `ExecuteDescribeDependents`, use `&atmosConfig` to pass the address of the value.
Learnt from: aknysh
Repo: cloudposse/atmos PR: 1405
File: internal/exec/describe_dependents_test.go:455-456
Timestamp: 2025-08-16T23:32:40.412Z
Learning: In the cloudposse/atmos Go codebase, `InitCliConfig` returns a `schema.AtmosConfiguration` value (not a pointer), while `ExecuteDescribeDependents` expects a `*schema.AtmosConfiguration` pointer parameter. Therefore, when passing the result of `InitCliConfig` to `ExecuteDescribeDependents`, use `&atmosConfig` to pass the address of the value.
Learnt from: aknysh
Repo: cloudposse/atmos PR: 1405
File: internal/exec/describe_dependents_test.go:651-652
Timestamp: 2025-08-16T23:33:07.477Z
Learning: In the cloudposse/atmos Go codebase, ExecuteDescribeDependents expects a pointer to AtmosConfiguration (*schema.AtmosConfiguration), so when calling it with a value returned by cfg.InitCliConfig (which returns schema.AtmosConfiguration), the address-of operator (&) is necessary: ExecuteDescribeDependents(&atmosConfig, ...).
📚 Learning: 2025-09-23T02:30:42.362Z
Learnt from: CR
Repo: cloudposse/atmos PR: 0
File: .cursor/rules/atmos-rules.mdc:0-0
Timestamp: 2025-09-23T02:30:42.362Z
Learning: Applies to **/*_test.go : Every new feature must include comprehensive unit tests

Applied to files:

  • tests/cli_describe_identity_test.go
📚 Learning: 2025-05-23T19:51:47.091Z
Learnt from: samtholiya
Repo: cloudposse/atmos PR: 1255
File: cmd/describe_affected_test.go:15-15
Timestamp: 2025-05-23T19:51:47.091Z
Learning: The atmos codebase has a custom extension to *testing.T that provides a Chdir method, allowing test functions to call t.Chdir() to change working directories during tests. This is used consistently across test files in the codebase.

Applied to files:

  • tests/cli_describe_identity_test.go
📚 Learning: 2025-09-23T02:30:42.362Z
Learnt from: CR
Repo: cloudposse/atmos PR: 0
File: .cursor/rules/atmos-rules.mdc:0-0
Timestamp: 2025-09-23T02:30:42.362Z
Learning: Applies to **/*_test.go : Use table-driven tests for multiple scenarios

Applied to files:

  • tests/cli_describe_identity_test.go
📚 Learning: 2025-09-07T18:07:00.549Z
Learnt from: Benbentwo
Repo: cloudposse/atmos PR: 1452
File: cmd/auth_login.go:43-44
Timestamp: 2025-09-07T18:07:00.549Z
Learning: In the atmos project, the identity flag is defined as a persistent flag on the auth root command (cmd/auth.go), making it available to all auth subcommands without needing to be redefined in each individual subcommand.

Applied to files:

  • tests/cli_describe_identity_test.go
📚 Learning: 2025-09-23T02:30:42.362Z
Learnt from: CR
Repo: cloudposse/atmos PR: 0
File: .cursor/rules/atmos-rules.mdc:0-0
Timestamp: 2025-09-23T02:30:42.362Z
Learning: Applies to **/*_test.go : Test both happy paths and error conditions

Applied to files:

  • tests/cli_describe_identity_test.go
📚 Learning: 2025-10-10T23:51:36.597Z
Learnt from: osterman
Repo: cloudposse/atmos PR: 1599
File: internal/exec/terraform.go:394-402
Timestamp: 2025-10-10T23:51:36.597Z
Learning: In Atmos (internal/exec/terraform.go), when adding OpenTofu-specific flags like `--var-file` for `init`, do not gate them based on command name (e.g., checking if `info.Command == "tofu"` or `info.Command == "opentofu"`) because command names don't reliably indicate the actual binary being executed (symlinks, aliases). Instead, document the OpenTofu requirement in code comments and documentation, trusting users who enable the feature (e.g., `PassVars`) to ensure their terraform command points to an OpenTofu binary.

Applied to files:

  • tests/cli_describe_identity_test.go
📚 Learning: 2024-11-13T21:37:07.852Z
Learnt from: Cerebrovinny
Repo: cloudposse/atmos PR: 764
File: internal/exec/describe_stacks.go:289-295
Timestamp: 2024-11-13T21:37:07.852Z
Learning: In the `internal/exec/describe_stacks.go` file of the `atmos` project written in Go, avoid extracting the stack name handling logic into a helper function within the `ExecuteDescribeStacks` method, even if the logic appears duplicated.

Applied to files:

  • tests/cli_describe_identity_test.go
📚 Learning: 2024-10-23T21:36:40.262Z
Learnt from: osterman
Repo: cloudposse/atmos PR: 740
File: cmd/cmd_utils.go:340-359
Timestamp: 2024-10-23T21:36:40.262Z
Learning: In the Go codebase for Atmos, when reviewing functions like `checkAtmosConfig` in `cmd/cmd_utils.go`, avoid suggesting refactoring to return errors instead of calling `os.Exit` if such changes would significantly increase the scope due to the need to update multiple call sites.

Applied to files:

  • tests/cli_describe_identity_test.go
📚 Learning: 2025-08-15T14:43:41.030Z
Learnt from: aknysh
Repo: cloudposse/atmos PR: 1352
File: pkg/store/artifactory_store_test.go:108-113
Timestamp: 2025-08-15T14:43:41.030Z
Learning: In test files for the atmos project, it's acceptable to ignore errors from os.Setenv/Unsetenv operations during test environment setup and teardown, as these are controlled test scenarios.

Applied to files:

  • tests/cli_describe_identity_test.go
📚 Learning: 2025-02-19T05:50:35.853Z
Learnt from: samtholiya
Repo: cloudposse/atmos PR: 1068
File: tests/snapshots/TestCLICommands_atmos_terraform_apply_--help.stdout.golden:0-0
Timestamp: 2025-02-19T05:50:35.853Z
Learning: Backtick formatting should only be applied to flag descriptions in Go source files, not in golden test files (test snapshots) as they are meant to capture the raw command output.

Applied to files:

  • tests/cli_describe_identity_test.go
📚 Learning: 2025-09-23T02:30:42.362Z
Learnt from: CR
Repo: cloudposse/atmos PR: 0
File: .cursor/rules/atmos-rules.mdc:0-0
Timestamp: 2025-09-23T02:30:42.362Z
Learning: Include integration tests for command flows and end-to-end CLI where possible

Applied to files:

  • tests/cli_describe_identity_test.go
📚 Learning: 2025-06-23T02:14:30.937Z
Learnt from: aknysh
Repo: cloudposse/atmos PR: 1327
File: cmd/terraform.go:111-117
Timestamp: 2025-06-23T02:14:30.937Z
Learning: In cmd/terraform.go, flags for the DescribeAffected function are added dynamically at runtime when info.Affected is true. This is intentional to avoid exposing internal flags like "file", "format", "verbose", "include-spacelift-admin-stacks", "include-settings", and "upload" in the terraform command interface, while still providing them for the shared DescribeAffected function used by both `atmos describe affected` and `atmos terraform apply --affected`.

Applied to files:

  • tests/cli_describe_identity_test.go
📚 Learning: 2025-10-07T00:25:16.333Z
Learnt from: osterman
Repo: cloudposse/atmos PR: 1498
File: website/src/components/Screengrabs/atmos-terraform-metadata--help.html:25-55
Timestamp: 2025-10-07T00:25:16.333Z
Learning: In Atmos CLI, subcommands inherit flags from their parent commands via Cobra's command inheritance. For example, `atmos terraform metadata --help` shows `--affected` and related flags inherited from the parent `terraform` command (defined in cmd/terraform.go), even though the metadata subcommand doesn't explicitly define these flags. This is expected Cobra behavior and auto-generated help screengrabs accurately reflect this inheritance.

Applied to files:

  • tests/cli_describe_identity_test.go
📚 Learning: 2025-01-09T22:27:25.538Z
Learnt from: samtholiya
Repo: cloudposse/atmos PR: 914
File: cmd/validate_stacks.go:20-23
Timestamp: 2025-01-09T22:27:25.538Z
Learning: The validate commands in Atmos can have different help handling implementations. Specifically, validate_component.go and validate_stacks.go are designed to handle help requests differently, with validate_stacks.go including positional argument checks while validate_component.go does not.

Applied to files:

  • tests/cli_describe_identity_test.go
🧬 Code graph analysis (1)
tests/cli_describe_identity_test.go (2)
tests/testhelpers/atmos_runner.go (1)
  • NewAtmosRunner (31-35)
pkg/logger/log.go (2)
  • Info (34-36)
  • Error (54-56)
⏰ 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). (8)
  • GitHub Check: Build (linux)
  • GitHub Check: Build (windows)
  • GitHub Check: Build (macos)
  • GitHub Check: Analyze (go)
  • GitHub Check: website-deploy-preview
  • GitHub Check: autofix
  • GitHub Check: Review Dependency Licenses
  • GitHub Check: Summary
🔇 Additional comments (1)
tests/cli_describe_identity_test.go (1)

24-66: Solid test coverage for identity flag behavior.

The table-driven tests properly verify that:

  • Commands fail gracefully with non-existent identity
  • No interactive selector appears when explicit identity is provided
  • Error assertions are present (addressing the previous review)

The test coverage aligns well with the PR objectives for identity flag support.

@aknysh aknysh requested a review from osterman November 3, 2025 15:44
@aknysh aknysh merged commit 4ee62fe into main Nov 3, 2025
54 checks passed
@aknysh aknysh deleted the fix-auth-terraform-state branch November 3, 2025 16:02
@mergify mergify bot removed the needs-cloudposse Needs Cloud Posse assistance label Nov 3, 2025
@github-actions
Copy link

github-actions bot commented Nov 3, 2025

These changes were released in v1.197.0.

@aknysh aknysh self-assigned this Nov 6, 2025
osterman pushed a commit that referenced this pull request Nov 13, 2025
These unit tests were written before authentication was added to describe
commands and need to explicitly opt out of authentication to work correctly.

## Problem

Tests TestDescribeAffected, TestDescribeDependents, and TestDescribeStacksRunnable
were failing with "authentication not configured in atmos.yaml" error. These tests
were written in June 2025 by Sam Tholiya before authentication existed. When
authentication was added to describe commands in PR #1742 (Nov 3, 2025), these
existing unit tests were not updated and began failing.

## Root Cause

Some tests bind viper to ATMOS_IDENTITY environment variable, and viper retains
this state across tests. When tests that set ATMOS_IDENTITY run first, subsequent
tests inherit this value through viper, causing authentication validation to run
even though the tests didn't configure authentication.

## Solution

Explicitly disable authentication in each test by:
- Setting ATMOS_IDENTITY=false via t.Setenv() to set environment variable
- Setting viper.Set("identity", "false") to ensure viper recognizes the disabled state
- This causes the identity value to be normalized to "__DISABLED__", which skips
  authentication validation

Also added empty auth: section to basic fixture to document that authentication
is not configured.

## Changes

- cmd/describe_affected_test.go: Add authentication disablement
- cmd/describe_dependents_test.go: Add authentication disablement
- cmd/describe_stacks_test.go: Add authentication disablement
- tests/fixtures/scenarios/basic/atmos.yaml: Add empty auth section with comment

These are unit tests that mock the execution layer, so they don't need real
authentication - they just need to opt out of it explicitly now that authentication
is part of the command flow.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

minor New features that do not break anything size/xl Extra large size PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants