Repository navigation
feat(dev-3124): Pin Terraform provider versions via required_providers - #1841
Conversation
Dependency Review✅ No vulnerabilities or license issues found.Scanned FilesNone |
|
Warning Rate limit exceededErik Osterman (Cloud Posse) (@osterman) has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 8 minutes and 7 seconds before requesting another review. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughAdds Terraform required_providers and required_version end-to-end: schema, config propagation, stack extraction/merge, generator framework (registry, writers, generators), CLI subcommand, and file generation for terraform_override.tf.json. Changes
Sequence Diagram(s)sequenceDiagram
participant CLI as CLI Command
participant Proc as Stack Processor
participant Config as Config/Schema
participant Reg as Generator Registry
participant Gen as RequiredProviders Generator
participant Writer as File Writer
CLI->>Proc: ProcessStacks(atmosConfig, stack)
Proc->>Config: Extract required_providers & required_version
Proc->>Config: Apply base inheritance & overrides
Proc->>Config: Merge precedence → final ComponentRequired*
Proc-->>CLI: Return processed stack info
CLI->>Reg: Generate(ctx, "required_providers", genCtx, writer)
Reg->>Gen: ShouldGenerate(genCtx)?
alt should generate
Reg->>Gen: Validate(genCtx)
Reg->>Gen: Generate(ctx, genCtx)
Gen-->>Reg: terraform block map
Reg->>Writer: WriteJSON(dir, filename, data)
Writer-->>Reg: OK
else skip
Reg-->>CLI: No generation needed
end
Reg-->>CLI: Done
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
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. |
|
Warning Changelog Entry RequiredThis PR is labeled Action needed: Add a new blog post in Example filename: Alternatively: If this change doesn't require a changelog entry, remove the |
|
💥 This pull request now has conflicts. Could you fix it Erik Osterman (Cloud Posse) (@osterman)? 🙏 |
There was a problem hiding this comment.
Actionable comments posted: 5
🧹 Nitpick comments (13)
pkg/generator/required_providers/generator_test.go (1)
148-156: Preferassert.ErrorIsoverassert.True(errors.Is(...)).Per coding guidelines, use
assert.ErrorIs(t, err, tt.errType)for cleaner assertions.if tt.wantErr { assert.Error(t, err) if tt.errType != nil { - assert.True(t, errors.Is(err, tt.errType)) + assert.ErrorIs(t, err, tt.errType) } } else { assert.NoError(t, err) }pkg/generator/generator_test.go (4)
145-156: Line 148 is a no-op assignment.
registryOnce = registryOncedoes nothing. If you intended to reset the sync.Once for testing, this won't work since sync.Once cannot be reset. The current approach of directly replacingregistryis sufficient.// Save and restore registry state. originalRegistry := registry - registryOnce = registryOnce // Reset for testing. defer func() { registry = originalRegistry }()
168-173: Useassert.ErrorIsfor consistency.t.Run("Get returns error for unknown generator", func(t *testing.T) { _, err := GetRegistry().Get("unknown") assert.Error(t, err) - assert.True(t, errors.Is(err, ErrGeneratorNotFound)) + assert.ErrorIs(t, err, ErrGeneratorNotFound) })
266-290: Similarly, useassert.ErrorIsfor validation and generation errors.err := GenerateAll(context.Background(), ctx, writer) assert.Error(t, err) - assert.True(t, errors.Is(err, ErrValidationFailed)) + assert.ErrorIs(t, err, ErrValidationFailed) }) t.Run("returns generation error", func(t *testing.T) { // ... err := GenerateAll(context.Background(), ctx, writer) assert.Error(t, err) - assert.True(t, errors.Is(err, ErrGenerationFailed)) + assert.ErrorIs(t, err, ErrGenerationFailed) })
371-376: Same pattern here for unknown generator error.err := Generate(context.Background(), "unknown", ctx, writer) assert.Error(t, err) - assert.True(t, errors.Is(err, ErrGeneratorNotFound)) + assert.ErrorIs(t, err, ErrGeneratorNotFound) })pkg/generator/options.go (1)
29-34: Consider a nil guard for ctx.If
ctxis nil, options will panic. A defensive check could prevent hard-to-trace crashes.// ApplyOptions applies functional options to a GeneratorContext. func ApplyOptions(ctx *GeneratorContext, opts ...Option) { + if ctx == nil { + return + } for _, opt := range opts { opt(ctx) } }internal/exec/stack_processor_process_stacks_helpers_overrides.go (1)
86-127: Consider consolidating Terraform-specific blocks.The four separate
if opts.ComponentType == cfg.TerraformComponentTypeblocks (providers, required_providers, required_version, hooks) could be combined into a single block. Not blocking, just a readability consideration.// Terraform-specific: extract providers overrides. if opts.ComponentType == cfg.TerraformComponentType { if i, ok := componentOverrides[cfg.ProvidersSectionName]; ok { componentOverridesProviders, ok := i.(map[string]any) if !ok { return fmt.Errorf("%w: 'components.%s.%s.overrides.providers' in the manifest '%s'", errUtils.ErrInvalidComponentOverridesProviders, opts.ComponentType, opts.Component, opts.StackName) } result.ComponentOverridesProviders = componentOverridesProviders } - } - // Terraform-specific: extract required_providers overrides (DEV-3124). - if opts.ComponentType == cfg.TerraformComponentType { + // Extract required_providers overrides (DEV-3124). if i, ok := componentOverrides[cfg.RequiredProvidersSectionName]; ok { // ... rest of extraction } - } - // Terraform-specific: extract required_version overrides (DEV-3124). - if opts.ComponentType == cfg.TerraformComponentType { + // Extract required_version overrides (DEV-3124). if i, ok := componentOverrides[cfg.RequiredVersionSectionName]; ok { // ... rest of extraction } - } - // Terraform-specific: extract hooks overrides. - if opts.ComponentType == cfg.TerraformComponentType { + // Extract hooks overrides. if i, ok := componentOverrides[cfg.HooksSectionName]; ok { // ... rest of extraction } }pkg/generator/registry.go (2)
36-41: Simplify redundantGetRegistry()calls.Inside
Register, you already hold the lock. CallingGetRegistry()multiple times is redundant and slightly less efficient.func Register(gen Generator) { - GetRegistry().mu.Lock() - defer GetRegistry().mu.Unlock() - GetRegistry().generators[gen.Name()] = gen + reg := GetRegistry() + reg.mu.Lock() + defer reg.mu.Unlock() + reg.generators[gen.Name()] = gen log.Debug("Registered generator", "name", gen.Name()) }
84-91: Use%wfor inner errors to preserve error chains.Using
%vfor the inner error loses the ability to unwrap it. Per Go error handling idioms, wrap errors with context using%w.if err := gen.Validate(genCtx); err != nil { - return fmt.Errorf("%w: generator %s: %v", ErrValidationFailed, name, err) + return fmt.Errorf("%w: generator %s: %w", ErrValidationFailed, name, err) } content, err := gen.Generate(ctx, genCtx) if err != nil { - return fmt.Errorf("%w: generator %s: %v", ErrGenerationFailed, name, err) + return fmt.Errorf("%w: generator %s: %w", ErrGenerationFailed, name, err) }Same pattern applies to lines 102, 125, 130, and 140.
pkg/generator/required_providers/generator.go (2)
90-97: Defensive validation is reasonable but adds overhead.
GeneratecallsValidateinternally, but the registry already validates before callingGenerate. Similarly, lines 94-97 duplicate theShouldGeneratecheck. This is defensive but consider whether the performance cost matters for your use case.If generators are always called through the registry (which validates first), you could skip the internal validation and rely on the registry's orchestration. However, keeping it defensive is also valid for direct usage.
105-111: Clarify the comment on type handling.The comment says "Convert map[string]map[string]any to map[string]any" but this isn't a conversion—it's assigning typed values to an
anycontainer. Consider simplifying:if len(genCtx.RequiredProviders) > 0 { - // Convert map[string]map[string]any to map[string]any for JSON serialization. - providers := make(map[string]any) - for name, config := range genCtx.RequiredProviders { - providers[name] = config - } - terraformBlock["required_providers"] = providers + // RequiredProviders values are already map[string]any; wrap in parent map. + terraformBlock["required_providers"] = genCtx.RequiredProviders }Since
genCtx.RequiredProvidersismap[string]map[string]any, you can assign it directly—JSON serialization handles it fine.pkg/generator/writer.go (1)
46-59: Consider using mockgen for consistency with codebase patterns.Per coding guidelines, mocks should be generated with
go.uber.org/mock/mockgen. The hand-rolledMockWriterworks fine but diverges from the established pattern.If you want to align with the codebase convention, add a
//go:generatedirective://go:generate mockgen -destination=mock_writer.go -package=generator github.com/cloudposse/atmos/pkg/generator WriterThat said, the hand-rolled mock is simple and works well for this use case—keeping it is also reasonable.
errors/errors.go (1)
287-287: Align Spacelift sentinel name with existing naming.You have existing sentinels like
ErrSpaceliftAdminStackWorkspaceNotEnabledandErrSpaceliftAdminStackComponentNotProvisioned, but this new one isErrInvalidSpaceLiftSettings(camel-cased as “SpaceLift”). Consider renaming for consistency:- ErrInvalidSpaceLiftSettings = errors.New("invalid spacelift settings section") + ErrInvalidSpaceliftSettings = errors.New("invalid spacelift settings section")Then update any new usages accordingly in this PR.
📜 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.
📒 Files selected for processing (29)
cmd/terraform/generate/required_providers/required_providers.go(1 hunks)cmd/terraform_generate.go(3 hunks)errors/errors.go(1 hunks)internal/exec/stack_processor_cache.go(1 hunks)internal/exec/stack_processor_merge.go(2 hunks)internal/exec/stack_processor_process_stacks_helpers.go(2 hunks)internal/exec/stack_processor_process_stacks_helpers_extraction.go(1 hunks)internal/exec/stack_processor_process_stacks_helpers_inheritance.go(2 hunks)internal/exec/stack_processor_process_stacks_helpers_overrides.go(2 hunks)internal/exec/stack_processor_utils.go(2 hunks)internal/exec/terraform.go(1 hunks)internal/exec/terraform_generate_required_providers.go(1 hunks)internal/exec/terraform_utils.go(3 hunks)internal/exec/utils.go(4 hunks)pkg/config/const.go(1 hunks)pkg/datafetcher/schema/stacks/stack-config/1.0.json(4 hunks)pkg/generator/errors.go(1 hunks)pkg/generator/generator.go(1 hunks)pkg/generator/generator_test.go(1 hunks)pkg/generator/options.go(1 hunks)pkg/generator/providers/generator.go(1 hunks)pkg/generator/providers/generator_test.go(1 hunks)pkg/generator/registry.go(1 hunks)pkg/generator/required_providers/generator.go(1 hunks)pkg/generator/required_providers/generator_test.go(1 hunks)pkg/generator/varfile/generator.go(1 hunks)pkg/generator/varfile/generator_test.go(1 hunks)pkg/generator/writer.go(1 hunks)pkg/schema/schema.go(2 hunks)
🧰 Additional context used
📓 Path-based instructions (4)
**/*.go
📄 CodeRabbit inference engine (.cursor/rules/atmos-rules.mdc)
**/*.go: Use Viper for managing configuration, environment variables, and flags in CLI commands
Use interfaces for external dependencies to facilitate mocking and consider using testify/mock for creating mock implementations
All code must pass golangci-lint checks
Follow Go's error handling idioms: use meaningful error messages, wrap errors with context usingfmt.Errorf("context: %w", err), and consider using custom error types for domain-specific errors
Follow standard Go coding style: usegofmtandgoimportsto format code, prefer short descriptive variable names, use kebab-case for command-line flags, and snake_case for environment variables
Document all exported functions, types, and methods following Go's documentation conventions
Document complex logic with inline comments in Go code
Support configuration via files, environment variables, and flags following the precedence order: flags > environment variables > config file > defaults
Provide clear error messages to users, include troubleshooting hints when appropriate, and log detailed errors for debugging
**/*.go: All comments must end with periods (enforced bygodotlinter)
Import organization: three groups separated by blank lines, sorted alphabetically: 1) Go stdlib, 2) 3rd-party (NOT cloudposse/atmos), 3) Atmos packages. Maintain aliases:cfg,log,u,errUtils
Adddefer perf.Track(atmosConfig, "pkg.FuncName")()+ blank line to all public functions. Usenilif no atmosConfig param
Keep files small and focused (<600 lines). One cmd/impl per file. Co-locate tests. Never use//revive:disable:file-length-limit
Use sentinel errors fromerrors/errors.gowith ErrorBuilder for all user-facing errors. Useerrors.Is()for checking errors, never string comparison.WithCause()preserves underlying error messages,WithExplanation()adds context,WithHint()provides guidance,WithContext()adds key-value pairs
Usecontext.Contextas first parameter for: cancellation signals (prop...
Files:
pkg/config/const.gointernal/exec/terraform_generate_required_providers.gopkg/schema/schema.gocmd/terraform_generate.gopkg/generator/varfile/generator_test.gocmd/terraform/generate/required_providers/required_providers.gointernal/exec/stack_processor_process_stacks_helpers_inheritance.gointernal/exec/terraform_utils.gointernal/exec/utils.gointernal/exec/stack_processor_process_stacks_helpers.gopkg/generator/registry.gopkg/generator/providers/generator.gopkg/generator/generator_test.gopkg/generator/generator.gopkg/generator/required_providers/generator_test.gopkg/generator/errors.gopkg/generator/writer.gopkg/generator/providers/generator_test.gointernal/exec/stack_processor_cache.gointernal/exec/stack_processor_merge.gointernal/exec/terraform.gopkg/generator/required_providers/generator.gopkg/generator/varfile/generator.gointernal/exec/stack_processor_process_stacks_helpers_overrides.gopkg/generator/options.gointernal/exec/stack_processor_process_stacks_helpers_extraction.gointernal/exec/stack_processor_utils.goerrors/errors.go
pkg/**/*.go
📄 CodeRabbit inference engine (CLAUDE.md)
pkg/**/*.go: Business logic packages must follow the Service-Oriented Architecture pattern with: one Service struct per domain, Provider interfaces for classes of problems, default implementations, mock implementations, and dependency injection for testability
Use interface-driven design: define interfaces for all major functionality, use dependency injection for testability, generate mocks withgo.uber.org/mock/mockgenwith//go:generatedirectives, avoid integration tests by mocking external dependencies
Create focused purpose-built packages inpkg/for new functionality, each with clear responsibility. DO NOT add new functions topkg/utils/orinternal/exec/. Each package should have focused business logic with tests
Implement registry pattern for extensibility and plugin-like architecture. Define interfaces for provider implementations, register implementations in registry, generate mocks with mockgen. Examples: Command Registry incmd/internal/registry.go, Store Registry inpkg/store/registry.go
Files:
pkg/config/const.gopkg/schema/schema.gopkg/generator/varfile/generator_test.gopkg/generator/registry.gopkg/generator/providers/generator.gopkg/generator/generator_test.gopkg/generator/generator.gopkg/generator/required_providers/generator_test.gopkg/generator/errors.gopkg/generator/writer.gopkg/generator/providers/generator_test.gopkg/generator/required_providers/generator.gopkg/generator/varfile/generator.gopkg/generator/options.go
cmd/**/*.go
📄 CodeRabbit inference engine (.cursor/rules/atmos-rules.mdc)
cmd/**/*.go: Use Cobra's recommended command structure with a root command and subcommands, implementing each command in a separate file undercmd/directory
Provide comprehensive help text for all commands and flags, include examples in command help, and follow Go's documentation conventions in Cobra command definitions
Provide meaningful feedback to users and include progress indicators for long-running operations in CLI commands
cmd/**/*.go: CLI command files must be thin wrappers that only handle CLI concerns (flags, arguments, command registration). All business logic must be delegated topkg/packages
Useflags.NewStandardParser()for command-specific flag parsing. NEVER callviper.BindEnv()orviper.BindPFlag()directly - use the unifiedpkg/flags/infrastructure instead. Register flags with Cobra command and bind to Viper for precedence handling
All CLI commands MUST implement the CommandProvider interface and register via command registry pattern incmd/internal/registry.go
Embed examples fromcmd/markdown/*_usage.mdusing//go:embed. Render withutils.PrintfMarkdown()
Files:
cmd/terraform_generate.gocmd/terraform/generate/required_providers/required_providers.go
**/*_test.go
📄 CodeRabbit inference engine (.cursor/rules/atmos-rules.mdc)
**/*_test.go: Every new feature must include comprehensive unit tests targeting >80% code coverage for all packages
Use table-driven tests for testing multiple scenarios in Go
Include integration tests for command flows and test CLI end-to-end when possible with test fixtures
**/*_test.go: Useassert.ErrorIs(t, err, ErrSentinel)for checking our own errors and stdlib errors. Only use string matching for third-party errors
NEVER useassert.Contains(err.Error(), ...)for error checking. ALWAYS useassert.ErrorIs()instead. NEVER use string comparison:err.Error() == "..."orstrings.Contains(err.Error(), ...)
Test behavior, not implementation. Never test stub functions - implement or remove. Avoid tautological tests. Make code testable using dependency injection to avoidos.Exit,CheckErrorPrintAndExit, external systems. Remove always-skipped tests - fix or delete. Table-driven tests must have real scenarios
Usego.uber.org/mock/mockgenwith//go:generatedirectives for mock generation. Never create manual mocks. Pattern://go:generate go run go.uber.org/mock/mockgen@latest -source=filename.go -destination=mock_filename_test.go
Use table-driven tests for comprehensive coverage. Tests must call actual production code, never duplicate logic. Target >80% test coverage (enforced by CodeCov)
Files:
pkg/generator/varfile/generator_test.gopkg/generator/generator_test.gopkg/generator/required_providers/generator_test.gopkg/generator/providers/generator_test.go
🧠 Learnings (54)
📓 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: 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: osterman
Repo: cloudposse/atmos PR: 801
File: examples/quick-start-advanced/Dockerfile:9-9
Timestamp: 2024-11-23T00:13:22.004Z
Learning: When updating the `ATMOS_VERSION` in Dockerfiles, the team prefers to pin to the next future version when the PR merges, even if the version is not yet released.
📚 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/terraform_generate_required_providers.gocmd/terraform_generate.gocmd/terraform/generate/required_providers/required_providers.gointernal/exec/terraform_utils.gointernal/exec/utils.gointernal/exec/stack_processor_process_stacks_helpers.gointernal/exec/terraform.gopkg/generator/varfile/generator.go
📚 Learning: 2025-12-06T19:24:49.343Z
Learnt from: CR
Repo: cloudposse/atmos PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-06T19:24:49.343Z
Learning: Applies to cmd/**/*.go : All CLI commands MUST implement the CommandProvider interface and register via command registry pattern in `cmd/internal/registry.go`
Applied to files:
internal/exec/terraform_generate_required_providers.gocmd/terraform_generate.gocmd/terraform/generate/required_providers/required_providers.go
📚 Learning: 2024-10-27T04:41:49.199Z
Learnt from: haitham911
Repo: cloudposse/atmos PR: 727
File: internal/exec/terraform_clean.go:215-223
Timestamp: 2024-10-27T04:41:49.199Z
Learning: In `internal/exec/terraform_clean.go`, the function `determineCleanPath` is necessary and should not be removed.
Applied to files:
internal/exec/terraform_generate_required_providers.gointernal/exec/terraform_utils.gointernal/exec/terraform.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:
internal/exec/terraform_generate_required_providers.gocmd/terraform_generate.gointernal/exec/terraform_utils.gointernal/exec/terraform.go
📚 Learning: 2025-01-09T22:37:01.004Z
Learnt from: samtholiya
Repo: cloudposse/atmos PR: 914
File: cmd/terraform_commands.go:260-265
Timestamp: 2025-01-09T22:37:01.004Z
Learning: In the terraform commands implementation (cmd/terraform_commands.go), the direct use of `os.Args[2:]` for argument handling is intentionally preserved to avoid extensive refactoring. While it could be improved to use cobra's argument parsing, such changes should be handled in a dedicated PR to maintain focus and minimize risk.
Applied to files:
internal/exec/terraform_generate_required_providers.gocmd/terraform_generate.gocmd/terraform/generate/required_providers/required_providers.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/terraform_generate_required_providers.gointernal/exec/terraform.gointernal/exec/stack_processor_process_stacks_helpers_extraction.go
📚 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_generate_required_providers.gointernal/exec/terraform_utils.gointernal/exec/stack_processor_process_stacks_helpers.gointernal/exec/terraform.gointernal/exec/stack_processor_process_stacks_helpers_overrides.gointernal/exec/stack_processor_process_stacks_helpers_extraction.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:
internal/exec/terraform_generate_required_providers.gocmd/terraform_generate.gointernal/exec/terraform_utils.gointernal/exec/stack_processor_process_stacks_helpers.gointernal/exec/terraform.gointernal/exec/stack_processor_process_stacks_helpers_overrides.gointernal/exec/stack_processor_process_stacks_helpers_extraction.go
📚 Learning: 2024-11-24T19:13:10.287Z
Learnt from: haitham911
Repo: cloudposse/atmos PR: 727
File: internal/exec/terraform_clean.go:407-416
Timestamp: 2024-11-24T19:13:10.287Z
Learning: In `internal/exec/terraform_clean.go`, when `getStackTerraformStateFolder` returns an error in the `handleCleanSubCommand` function, the error is logged, and the process continues without returning the error.
Applied to files:
internal/exec/terraform_generate_required_providers.go
📚 Learning: 2025-12-06T19:24:49.343Z
Learnt from: CR
Repo: cloudposse/atmos PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-06T19:24:49.343Z
Learning: Applies to **/*.go : New configs support Go templating with `FuncMap()` from `internal/exec/template_funcs.go`. Implement template functions in `internal/exec/template_funcs.go`, register them, add tests, and update documentation
Applied to files:
internal/exec/terraform_generate_required_providers.gopkg/generator/varfile/generator_test.gointernal/exec/terraform_utils.gointernal/exec/utils.gopkg/generator/generator.gopkg/generator/options.go
📚 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:
pkg/schema/schema.gointernal/exec/stack_processor_process_stacks_helpers_inheritance.gointernal/exec/utils.gointernal/exec/stack_processor_process_stacks_helpers.gointernal/exec/stack_processor_cache.gointernal/exec/stack_processor_merge.gointernal/exec/stack_processor_process_stacks_helpers_overrides.gointernal/exec/stack_processor_process_stacks_helpers_extraction.gointernal/exec/stack_processor_utils.goerrors/errors.go
📚 Learning: 2025-12-06T19:24:49.343Z
Learnt from: CR
Repo: cloudposse/atmos PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-06T19:24:49.343Z
Learning: Applies to pkg/datafetcher/schema/*.go : Update all schemas in `pkg/datafetcher/schema/` when adding config options
Applied to files:
pkg/schema/schema.gopkg/generator/options.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:
cmd/terraform_generate.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:
cmd/terraform_generate.go
📚 Learning: 2025-12-06T19:24:49.343Z
Learnt from: CR
Repo: cloudposse/atmos PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-06T19:24:49.343Z
Learning: Applies to **/*.go : Use `viper.BindEnv("ATMOS_VAR", "ATMOS_VAR", "FALLBACK")` for environment variables - ATMOS_ prefix required. Configuration loading precedence: CLI flags → ENV vars → config files → defaults
Applied to files:
cmd/terraform_generate.gointernal/exec/terraform.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:
cmd/terraform_generate.go
📚 Learning: 2025-11-24T17:35:37.209Z
Learnt from: CR
Repo: cloudposse/atmos PR: 0
File: .cursor/rules/atmos-rules.mdc:0-0
Timestamp: 2025-11-24T17:35:37.209Z
Learning: Applies to cmd/**/*.go : Provide comprehensive help text for all commands and flags, include examples in command help, and follow Go's documentation conventions in Cobra command definitions
Applied to files:
cmd/terraform_generate.go
📚 Learning: 2025-11-24T17:35:37.209Z
Learnt from: CR
Repo: cloudposse/atmos PR: 0
File: .cursor/rules/atmos-rules.mdc:0-0
Timestamp: 2025-11-24T17:35:37.209Z
Learning: Applies to **/*.go : Use Viper for managing configuration, environment variables, and flags in CLI commands
Applied to files:
cmd/terraform_generate.go
📚 Learning: 2025-11-24T17:35:37.209Z
Learnt from: CR
Repo: cloudposse/atmos PR: 0
File: .cursor/rules/atmos-rules.mdc:0-0
Timestamp: 2025-11-24T17:35:37.209Z
Learning: Applies to **/*_test.go : Use table-driven tests for testing multiple scenarios in Go
Applied to files:
pkg/generator/varfile/generator_test.gopkg/generator/generator_test.gopkg/generator/required_providers/generator_test.gopkg/generator/providers/generator_test.go
📚 Learning: 2025-11-24T17:35:37.209Z
Learnt from: CR
Repo: cloudposse/atmos PR: 0
File: .cursor/rules/atmos-rules.mdc:0-0
Timestamp: 2025-11-24T17:35:37.209Z
Learning: Applies to **/*_test.go : Every new feature must include comprehensive unit tests targeting >80% code coverage for all packages
Applied to files:
pkg/generator/varfile/generator_test.gopkg/generator/generator_test.gopkg/generator/required_providers/generator_test.gopkg/generator/providers/generator_test.go
📚 Learning: 2025-12-06T19:24:49.343Z
Learnt from: CR
Repo: cloudposse/atmos PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-06T19:24:49.343Z
Learning: Applies to **/*_test.go : Use table-driven tests for comprehensive coverage. Tests must call actual production code, never duplicate logic. Target >80% test coverage (enforced by CodeCov)
Applied to files:
pkg/generator/varfile/generator_test.gopkg/generator/generator_test.gopkg/generator/required_providers/generator_test.gopkg/generator/providers/generator_test.go
📚 Learning: 2025-12-06T19:24:49.343Z
Learnt from: CR
Repo: cloudposse/atmos PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-06T19:24:49.343Z
Learning: Applies to **/*_test.go : Test behavior, not implementation. Never test stub functions - implement or remove. Avoid tautological tests. Make code testable using dependency injection to avoid `os.Exit`, `CheckErrorPrintAndExit`, external systems. Remove always-skipped tests - fix or delete. Table-driven tests must have real scenarios
Applied to files:
pkg/generator/varfile/generator_test.gopkg/generator/generator_test.gopkg/generator/required_providers/generator_test.gopkg/generator/providers/generator_test.go
📚 Learning: 2025-11-24T17:35:37.209Z
Learnt from: CR
Repo: cloudposse/atmos PR: 0
File: .cursor/rules/atmos-rules.mdc:0-0
Timestamp: 2025-11-24T17:35:37.209Z
Learning: Applies to **/*_test.go : Include integration tests for command flows and test CLI end-to-end when possible with test fixtures
Applied to files:
pkg/generator/varfile/generator_test.gopkg/generator/generator_test.gopkg/generator/providers/generator_test.go
📚 Learning: 2025-12-06T19:24:49.343Z
Learnt from: CR
Repo: cloudposse/atmos PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-06T19:24:49.343Z
Learning: Applies to **/*_test.go : Use `go.uber.org/mock/mockgen` with `//go:generate` directives for mock generation. Never create manual mocks. Pattern: `//go:generate go run go.uber.org/mock/mockgenlatest -source=filename.go -destination=mock_filename_test.go`
Applied to files:
pkg/generator/varfile/generator_test.gopkg/generator/generator_test.gopkg/generator/required_providers/generator_test.gopkg/generator/providers/generator_test.go
📚 Learning: 2025-12-06T19:24:49.343Z
Learnt from: CR
Repo: cloudposse/atmos PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-06T19:24:49.343Z
Learning: Applies to pkg/**/*.go : Use interface-driven design: define interfaces for all major functionality, use dependency injection for testability, generate mocks with `go.uber.org/mock/mockgen` with `//go:generate` directives, avoid integration tests by mocking external dependencies
Applied to files:
pkg/generator/varfile/generator_test.gopkg/generator/generator_test.gopkg/generator/writer.go
📚 Learning: 2025-11-24T17:35:37.209Z
Learnt from: CR
Repo: cloudposse/atmos PR: 0
File: .cursor/rules/atmos-rules.mdc:0-0
Timestamp: 2025-11-24T17:35:37.209Z
Learning: Applies to cmd/**/*.go : Use Cobra's recommended command structure with a root command and subcommands, implementing each command in a separate file under `cmd/` directory
Applied to files:
cmd/terraform/generate/required_providers/required_providers.go
📚 Learning: 2025-10-08T06:48:07.499Z
Learnt from: aknysh
Repo: cloudposse/atmos PR: 1602
File: internal/exec/stack_processor_utils.go:968-1003
Timestamp: 2025-10-08T06:48:07.499Z
Learning: The `FindComponentDependenciesLegacy` function in `internal/exec/stack_processor_utils.go` is legacy code that is not actively used and is kept only for backward compatibility purposes.
Applied to files:
internal/exec/stack_processor_process_stacks_helpers_inheritance.gointernal/exec/utils.gointernal/exec/stack_processor_process_stacks_helpers.gointernal/exec/stack_processor_cache.gointernal/exec/stack_processor_process_stacks_helpers_extraction.gointernal/exec/stack_processor_utils.go
📚 Learning: 2025-12-06T19:24:49.343Z
Learnt from: CR
Repo: cloudposse/atmos PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-06T19:24:49.343Z
Learning: Applies to **/*.go : Follow multi-provider registry pattern: 1) Define interface in dedicated package, 2) Implement per provider, 3) Register implementations, 4) Generate mocks. Example: `pkg/store/` with AWS SSM, Azure Key Vault, Google Secret Manager
Applied to files:
internal/exec/terraform_utils.gopkg/generator/registry.gopkg/generator/providers/generator.gopkg/generator/required_providers/generator_test.gopkg/generator/providers/generator_test.gopkg/generator/required_providers/generator.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_utils.gopkg/generator/generator.gointernal/exec/terraform.go
📚 Learning: 2025-12-06T19:24:49.343Z
Learnt from: CR
Repo: cloudposse/atmos PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-06T19:24:49.343Z
Learning: Applies to **/*.go : Import organization: three groups separated by blank lines, sorted alphabetically: 1) Go stdlib, 2) 3rd-party (NOT cloudposse/atmos), 3) Atmos packages. Maintain aliases: `cfg`, `log`, `u`, `errUtils`
Applied to files:
internal/exec/terraform_utils.gopkg/generator/generator.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:
internal/exec/terraform_utils.gointernal/exec/terraform.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:
internal/exec/terraform_utils.gointernal/exec/terraform.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:
internal/exec/terraform_utils.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:
internal/exec/terraform_utils.gointernal/exec/terraform.go
📚 Learning: 2025-11-08T19:56:18.660Z
Learnt from: osterman
Repo: cloudposse/atmos PR: 1697
File: internal/exec/oci_utils.go:0-0
Timestamp: 2025-11-08T19:56:18.660Z
Learning: In the Atmos codebase, when a function receives an `*schema.AtmosConfiguration` parameter, it should read configuration values from `atmosConfig.Settings` fields rather than using direct `os.Getenv()` or `viper.GetString()` calls. The Atmos pattern is: viper.BindEnv in cmd/root.go binds environment variables → Viper unmarshals into atmosConfig.Settings via mapstructure → business logic reads from the Settings struct. This provides centralized config management, respects precedence, and enables testability. Example: `atmosConfig.Settings.AtmosGithubToken` instead of `os.Getenv("ATMOS_GITHUB_TOKEN")` in functions like `getGHCRAuth` in internal/exec/oci_utils.go.
Applied to files:
internal/exec/terraform_utils.gointernal/exec/terraform.go
📚 Learning: 2025-12-06T19:24:49.343Z
Learnt from: CR
Repo: cloudposse/atmos PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-06T19:24:49.343Z
Learning: Applies to pkg/**/*.go : Implement registry pattern for extensibility and plugin-like architecture. Define interfaces for provider implementations, register implementations in registry, generate mocks with mockgen. Examples: Command Registry in `cmd/internal/registry.go`, Store Registry in `pkg/store/registry.go`
Applied to files:
internal/exec/terraform_utils.gopkg/generator/registry.gopkg/generator/providers/generator.gopkg/generator/generator_test.gopkg/generator/generator.gopkg/generator/required_providers/generator_test.gopkg/generator/providers/generator_test.go
📚 Learning: 2024-11-19T23:00:45.899Z
Learnt from: osterman
Repo: cloudposse/atmos PR: 795
File: internal/exec/stack_processor_utils.go:378-386
Timestamp: 2024-11-19T23:00:45.899Z
Learning: In the `ProcessYAMLConfigFile` function within `internal/exec/stack_processor_utils.go`, directory traversal in stack imports is acceptable and should not be restricted.
Applied to files:
internal/exec/utils.go
📚 Learning: 2025-12-06T19:24:49.343Z
Learnt from: CR
Repo: cloudposse/atmos PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-06T19:24:49.343Z
Learning: Applies to **/*.go : Use functional options pattern for configuration instead of many parameters. Provide defaults and extensibility without breaking changes. Pattern: `type Option func(*Config)`, `func WithName(val) Option { return func(c *Config) { c.Name = val } }`, `func New(opts ...Option) { cfg := &Config{/*defaults*/}; for _, opt := range opts { opt(cfg) }; return &Client{config: cfg} }`
Applied to files:
internal/exec/utils.gopkg/generator/options.go
📚 Learning: 2024-12-08T14:26:16.972Z
Learnt from: pkbhowmick
Repo: cloudposse/atmos PR: 828
File: pkg/schema/schema.go:98-100
Timestamp: 2024-12-08T14:26:16.972Z
Learning: The `ListConfig` columns array in the `Components` struct can be empty.
Applied to files:
internal/exec/stack_processor_process_stacks_helpers.go
📚 Learning: 2025-11-24T17:35:37.209Z
Learnt from: CR
Repo: cloudposse/atmos PR: 0
File: .cursor/rules/atmos-rules.mdc:0-0
Timestamp: 2025-11-24T17:35:37.209Z
Learning: Applies to **/*.go : Use interfaces for external dependencies to facilitate mocking and consider using testify/mock for creating mock implementations
Applied to files:
pkg/generator/generator_test.go
📚 Learning: 2025-12-06T19:24:49.343Z
Learnt from: CR
Repo: cloudposse/atmos PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-06T19:24:49.343Z
Learning: Applies to pkg/**/*.go : Create focused purpose-built packages in `pkg/` for new functionality, each with clear responsibility. DO NOT add new functions to `pkg/utils/` or `internal/exec/`. Each package should have focused business logic with tests
Applied to files:
pkg/generator/generator_test.gopkg/generator/options.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:
pkg/generator/generator_test.go
📚 Learning: 2025-11-10T23:23:39.771Z
Learnt from: osterman
Repo: cloudposse/atmos PR: 1686
File: toolchain/registry/aqua/aqua_test.go:417-442
Timestamp: 2025-11-10T23:23:39.771Z
Learning: In Atmos toolchain AquaRegistry, tests should not hit real GitHub. Use the options pattern via WithGitHubBaseURL to inject an httptest server URL and make GetLatestVersion/GetAvailableVersions deterministic.
Applied to files:
pkg/generator/generator_test.gopkg/generator/required_providers/generator_test.go
📚 Learning: 2025-11-24T17:35:37.209Z
Learnt from: CR
Repo: cloudposse/atmos PR: 0
File: .cursor/rules/atmos-rules.mdc:0-0
Timestamp: 2025-11-24T17:35:37.209Z
Learning: Applies to **/*.go : Follow Go's error handling idioms: use meaningful error messages, wrap errors with context using `fmt.Errorf("context: %w", err)`, and consider using custom error types for domain-specific errors
Applied to files:
pkg/generator/errors.go
📚 Learning: 2025-12-06T19:24:49.343Z
Learnt from: CR
Repo: cloudposse/atmos PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-06T19:24:49.343Z
Learning: Applies to **/*.go : Use sentinel errors from `errors/errors.go` with ErrorBuilder for all user-facing errors. Use `errors.Is()` for checking errors, never string comparison. `WithCause()` preserves underlying error messages, `WithExplanation()` adds context, `WithHint()` provides guidance, `WithContext()` adds key-value pairs
Applied to files:
pkg/generator/errors.goerrors/errors.go
📚 Learning: 2025-10-02T19:17:51.630Z
Learnt from: osterman
Repo: cloudposse/atmos PR: 1504
File: pkg/profiler/profiler.go:20-31
Timestamp: 2025-10-02T19:17:51.630Z
Learning: In pkg/profiler/profiler.go, profiler-specific errors (ErrUnsupportedProfileType, ErrStartCPUProfile, ErrStartTraceProfile, ErrCreateProfileFile) must remain local and cannot be moved to errors/errors.go due to an import cycle: pkg/profiler → errors → pkg/schema → pkg/profiler. This is a valid exception to the centralized errors policy.
Applied to files:
pkg/generator/errors.go
📚 Learning: 2025-11-24T17:35:37.209Z
Learnt from: CR
Repo: cloudposse/atmos PR: 0
File: .cursor/rules/atmos-rules.mdc:0-0
Timestamp: 2025-11-24T17:35:37.209Z
Learning: Applies to **/*.go : Provide clear error messages to users, include troubleshooting hints when appropriate, and log detailed errors for debugging
Applied to files:
pkg/generator/errors.go
📚 Learning: 2025-04-26T15:54:10.506Z
Learnt from: haitham911
Repo: cloudposse/atmos PR: 1195
File: internal/exec/terraform_clean.go:99-99
Timestamp: 2025-04-26T15:54:10.506Z
Learning: The error variable `ErrRelPath` is defined in `internal/exec/terraform_clean_util.go` and is used across files in the `exec` package, including in `terraform_clean.go`. This is part of an approach to standardize error handling in the codebase.
Applied to files:
pkg/generator/errors.gointernal/exec/terraform.goerrors/errors.go
📚 Learning: 2025-12-06T19:24:49.343Z
Learnt from: CR
Repo: cloudposse/atmos PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-06T19:24:49.343Z
Learning: Applies to **/*.go : For output: Pipeable data → `data.*` (stdout), Plain UI → `ui.Write*()` (stderr), Status messages → `ui.Success/Error/Warning/Info()` (stderr), Formatted docs → `ui.Markdown*()`. Use `data.Write()`, `data.Writef()`, `data.Writeln()`, `data.WriteJSON()`, `data.WriteYAML()` for data output
Applied to files:
pkg/generator/writer.go
📚 Learning: 2025-11-24T17:35:37.209Z
Learnt from: CR
Repo: cloudposse/atmos PR: 0
File: .cursor/rules/atmos-rules.mdc:0-0
Timestamp: 2025-11-24T17:35:37.209Z
Learning: Applies to {go.mod,go.sum} : Manage dependencies with Go modules and keep dependencies up to date while minimizing external dependencies
Applied to files:
internal/exec/stack_processor_merge.go
📚 Learning: 2024-11-02T15:35:09.958Z
Learnt from: aknysh
Repo: cloudposse/atmos PR: 759
File: internal/exec/terraform.go:366-368
Timestamp: 2024-11-02T15:35:09.958Z
Learning: In `internal/exec/terraform.go`, the workspace cleaning code under both the general execution path and within the `case "init":` block is intentionally duplicated because the code execution paths are different. The `.terraform/environment` file should be deleted before executing `terraform init` in both scenarios to ensure a clean state.
Applied to files:
internal/exec/terraform.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.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/terraform.go
🧬 Code graph analysis (14)
pkg/schema/schema.go (1)
pkg/auth/types/interfaces.go (1)
AuthManager(173-282)
cmd/terraform_generate.go (1)
cmd/terraform/generate/required_providers/required_providers.go (1)
NewRequiredProvidersCommand(13-44)
cmd/terraform/generate/required_providers/required_providers.go (1)
internal/exec/terraform_generate_required_providers.go (1)
ExecuteTerraformGenerateRequiredProvidersCmd(20-111)
internal/exec/terraform_utils.go (6)
pkg/schema/schema.go (2)
AtmosConfiguration(53-96)ConfigAndStacksInfo(646-748)pkg/generator/providers/generator.go (2)
DefaultFilenameConst(16-16)Name(14-14)pkg/generator/required_providers/generator.go (2)
DefaultFilenameConst(17-17)Name(15-15)pkg/generator/generator.go (1)
NewGeneratorContext(88-109)pkg/generator/registry.go (1)
Generate(111-145)pkg/generator/writer.go (1)
NewFileWriter(24-32)
internal/exec/utils.go (1)
pkg/config/const.go (2)
RequiredProvidersSectionName(86-86)RequiredVersionSectionName(85-85)
pkg/generator/providers/generator.go (4)
pkg/generator/generator.go (2)
Generator(22-39)GeneratorContext(42-85)pkg/generator/registry.go (2)
Register(36-41)Generate(111-145)pkg/perf/perf.go (1)
Track(121-138)pkg/generator/errors.go (1)
ErrInvalidContext(11-11)
pkg/generator/generator_test.go (5)
pkg/generator/generator.go (7)
GeneratorContext(42-85)NewGeneratorContext(88-109)FormatJSON(16-16)Format(12-12)NewGeneratorContextWithOptions(112-121)FormatHCL(18-18)Generator(22-39)pkg/generator/registry.go (3)
Generate(111-145)GetRegistry(25-32)GenerateAll(69-108)pkg/generator/options.go (5)
WithFormat(9-13)WithDryRun(16-20)ApplyOptions(30-34)WithWorkingDir(23-27)WithFileMode(40-44)pkg/generator/writer.go (1)
NewMockWriter(55-59)pkg/generator/errors.go (3)
ErrGeneratorNotFound(8-8)ErrValidationFailed(14-14)ErrGenerationFailed(17-17)
pkg/generator/generator.go (3)
pkg/generator/registry.go (1)
Generate(111-145)pkg/schema/schema.go (3)
Context(504-519)Validate(219-221)ConfigAndStacksInfo(646-748)pkg/generator/options.go (2)
Option(6-6)ApplyOptions(30-34)
pkg/generator/providers/generator_test.go (4)
pkg/generator/generator.go (2)
Generator(22-39)GeneratorContext(42-85)pkg/generator/providers/generator.go (2)
Generator(20-20)Name(14-14)pkg/generator/errors.go (1)
ErrInvalidContext(11-11)pkg/generator/registry.go (2)
Generate(111-145)GetRegistry(25-32)
internal/exec/stack_processor_cache.go (1)
pkg/merge/merge.go (1)
DeepCopyMap(29-45)
pkg/generator/required_providers/generator.go (4)
pkg/generator/generator.go (2)
Generator(22-39)GeneratorContext(42-85)pkg/generator/registry.go (2)
Register(36-41)Generate(111-145)pkg/perf/perf.go (1)
Track(121-138)pkg/generator/errors.go (2)
ErrInvalidContext(11-11)ErrMissingProviderSource(32-32)
internal/exec/stack_processor_process_stacks_helpers_overrides.go (2)
pkg/config/const.go (3)
TerraformComponentType(57-57)RequiredProvidersSectionName(86-86)RequiredVersionSectionName(85-85)errors/errors.go (2)
ErrInvalidComponentOverridesRequiredProviders(282-282)ErrInvalidComponentOverridesRequiredVersion(283-283)
pkg/generator/options.go (2)
pkg/generator/generator.go (2)
GeneratorContext(42-85)Format(12-12)pkg/generator/writer.go (1)
FileWriter(19-21)
internal/exec/stack_processor_utils.go (3)
pkg/config/const.go (2)
RequiredProvidersSectionName(86-86)RequiredVersionSectionName(85-85)errors/errors.go (2)
ErrInvalidComponentRequiredProviders(265-265)ErrInvalidComponentRequiredVersion(266-266)pkg/merge/merge.go (1)
Merge(389-427)
⏰ Context from checks skipped due to timeout of 900000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: Acceptance Tests (windows)
- GitHub Check: Summary
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
pkg/generator/required_providers/generator.go (1)
108-115: Consider simplifying the provider assignment.The loop converting
genCtx.RequiredProvidersto a new map appears unnecessary since both the source and destination types are compatible for JSON serialization. You could directly assign:- if len(genCtx.RequiredProviders) > 0 { - // Convert map[string]map[string]any to map[string]any for JSON serialization. - providers := make(map[string]any) - for name, config := range genCtx.RequiredProviders { - providers[name] = config - } - terraformBlock["required_providers"] = providers - } + if len(genCtx.RequiredProviders) > 0 { + terraformBlock["required_providers"] = genCtx.RequiredProviders + }
📜 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.
📒 Files selected for processing (15)
cmd/terraform/generate/generate.go(2 hunks)errors/errors.go(2 hunks)internal/exec/terraform.go(1 hunks)internal/exec/terraform_generate_required_providers.go(1 hunks)internal/exec/terraform_utils.go(3 hunks)internal/exec/utils.go(4 hunks)pkg/config/const.go(1 hunks)pkg/datafetcher/schema/stacks/stack-config/1.0.json(4 hunks)pkg/generator/errors.go(1 hunks)pkg/generator/generator.go(1 hunks)pkg/generator/providers/generator.go(1 hunks)pkg/generator/registry.go(1 hunks)pkg/generator/required_providers/generator.go(1 hunks)pkg/generator/varfile/generator.go(1 hunks)pkg/schema/schema.go(2 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
- pkg/config/const.go
- pkg/schema/schema.go
- pkg/generator/providers/generator.go
🧰 Additional context used
📓 Path-based instructions (2)
cmd/**/*.go
📄 CodeRabbit inference engine (.cursor/rules/atmos-rules.mdc)
cmd/**/*.go: Use Cobra's recommended command structure with a root command and subcommands, implementing each command in a separate file undercmd/directory
Provide comprehensive help text for all commands and flags, include examples in command help, and follow Go's documentation conventions in Cobra command definitions
Provide meaningful feedback to users and include progress indicators for long-running operations in CLI commands
cmd/**/*.go: Commands MUST use flags.NewStandardParser() for command-specific flags; NEVER call viper.BindEnv() or viper.BindPFlag() directly (Forbidigo enforces this); see cmd/version/version.go for reference
Embed CLI examples from cmd/markdown/*_usage.md using //go:embed; render with utils.PrintfMarkdown()
Files:
cmd/terraform/generate/generate.go
**/*.go
📄 CodeRabbit inference engine (.cursor/rules/atmos-rules.mdc)
**/*.go: Use Viper for managing configuration, environment variables, and flags in CLI commands
Use interfaces for external dependencies to facilitate mocking and consider using testify/mock for creating mock implementations
All code must pass golangci-lint checks
Follow Go's error handling idioms: use meaningful error messages, wrap errors with context usingfmt.Errorf("context: %w", err), and consider using custom error types for domain-specific errors
Follow standard Go coding style: usegofmtandgoimportsto format code, prefer short descriptive variable names, use kebab-case for command-line flags, and snake_case for environment variables
Document all exported functions, types, and methods following Go's documentation conventions
Document complex logic with inline comments in Go code
Support configuration via files, environment variables, and flags following the precedence order: flags > environment variables > config file > defaults
Provide clear error messages to users, include troubleshooting hints when appropriate, and log detailed errors for debugging
**/*.go: NEVER use fmt.Fprintf(os.Stdout/Stderr) or fmt.Println(); use data.* or ui.* functions instead
All comments must end with periods (enforced by godot linter)
Organize imports in three groups separated by blank lines, sorted alphabetically: 1) Go stdlib, 2) 3rd-party (NOT cloudposse/atmos), 3) Atmos packages; maintain aliases: cfg, log, u, errUtils
Adddefer perf.Track(atmosConfig, "pkg.FuncName")()+ blank line to all public functions for performance tracking; use nil if no atmosConfig param
All errors MUST be wrapped using static errors defined in errors/errors.go; use errors.Join for combining multiple errors; use fmt.Errorf with %w for adding string context; use error builder for complex errors; use errors.Is() for error checking; NEVER use dynamic errors directly
Use go.uber.org/mock/mockgen with //go:generate directives for mock generation; never create manual mocks
Keep files small...
Files:
cmd/terraform/generate/generate.gopkg/generator/varfile/generator.gopkg/generator/errors.gopkg/generator/required_providers/generator.gointernal/exec/terraform.gointernal/exec/terraform_generate_required_providers.gopkg/generator/generator.gopkg/generator/registry.goerrors/errors.gointernal/exec/terraform_utils.gointernal/exec/utils.go
🧠 Learnings (45)
📓 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: osterman
Repo: cloudposse/atmos PR: 801
File: examples/quick-start-advanced/Dockerfile:9-9
Timestamp: 2024-11-23T00:13:22.004Z
Learning: When updating the `ATMOS_VERSION` in Dockerfiles, the team prefers to pin to the next future version when the PR merges, even if the version is not yet released.
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: 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.
📚 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:
cmd/terraform/generate/generate.go
📚 Learning: 2025-11-24T17:35:37.209Z
Learnt from: CR
Repo: cloudposse/atmos PR: 0
File: .cursor/rules/atmos-rules.mdc:0-0
Timestamp: 2025-11-24T17:35:37.209Z
Learning: Applies to cmd/**/*.go : Use Cobra's recommended command structure with a root command and subcommands, implementing each command in a separate file under `cmd/` directory
Applied to files:
cmd/terraform/generate/generate.go
📚 Learning: 2025-01-09T22:37:01.004Z
Learnt from: samtholiya
Repo: cloudposse/atmos PR: 914
File: cmd/terraform_commands.go:260-265
Timestamp: 2025-01-09T22:37:01.004Z
Learning: In the terraform commands implementation (cmd/terraform_commands.go), the direct use of `os.Args[2:]` for argument handling is intentionally preserved to avoid extensive refactoring. While it could be improved to use cobra's argument parsing, such changes should be handled in a dedicated PR to maintain focus and minimize risk.
Applied to files:
cmd/terraform/generate/generate.gointernal/exec/terraform_generate_required_providers.go
📚 Learning: 2025-11-24T17:35:37.209Z
Learnt from: CR
Repo: cloudposse/atmos PR: 0
File: .cursor/rules/atmos-rules.mdc:0-0
Timestamp: 2025-11-24T17:35:37.209Z
Learning: Applies to cmd/**/*.go : Provide comprehensive help text for all commands and flags, include examples in command help, and follow Go's documentation conventions in Cobra command definitions
Applied to files:
cmd/terraform/generate/generate.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:
cmd/terraform/generate/generate.gointernal/exec/terraform.gointernal/exec/terraform_generate_required_providers.gopkg/generator/generator.gointernal/exec/terraform_utils.gointernal/exec/utils.go
📚 Learning: 2025-12-13T03:21:27.620Z
Learnt from: osterman
Repo: cloudposse/atmos PR: 1813
File: cmd/terraform/shell.go:28-73
Timestamp: 2025-12-13T03:21:27.620Z
Learning: In Atmos, when initializing CLI config via cfg.InitCliConfig, always first populate the ConfigAndStacksInfo struct with global flag values by calling flags.ParseGlobalFlags(cmd, v) before LoadConfig. LoadConfig (pkg/config/load.go) reads config selection fields (AtmosConfigFilesFromArg, AtmosConfigDirsFromArg, BasePath, ProfilesFromArg) from the ConfigAndStacksInfo struct, not from Viper. Passing an empty struct causes the --base-path, --config, --config-path, and --profile flags to be ignored. Recommended pattern: parse flags → populate struct → call InitCliConfig. See cmd/terraform/plan_diff.go for reference implementation.
Applied to files:
cmd/terraform/generate/generate.go
📚 Learning: 2025-12-13T04:37:40.435Z
Learnt from: osterman
Repo: cloudposse/atmos PR: 1686
File: cmd/toolchain/get.go:23-40
Timestamp: 2025-12-13T04:37:40.435Z
Learning: In Go CLI command files using Cobra, constrain the subcommand to accept at most one positional argument (MaximumNArgs(1)) so it supports both listing all items (zero args) and fetching a specific item (one arg). Define and parse flags with a standard parser (e.g., flags.NewStandardParser()) and avoid binding flags to Viper (no viper.BindEnv/BindPFlag). This promotes explicit argument handling and predictable flag behavior across command files.
Applied to files:
cmd/terraform/generate/generate.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:
cmd/terraform/generate/generate.gointernal/exec/terraform.gointernal/exec/terraform_generate_required_providers.gointernal/exec/terraform_utils.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/terraform/generate/generate.gointernal/exec/terraform_utils.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:
cmd/terraform/generate/generate.go
📚 Learning: 2024-10-30T13:25:45.965Z
Learnt from: osterman
Repo: cloudposse/atmos PR: 727
File: internal/exec/terraform_clean.go:405-412
Timestamp: 2024-10-30T13:25:45.965Z
Learning: In `internal/exec/terraform_clean.go`, when appending `stackFolders` to `folders` in the `handleCleanSubCommand` function, it's unnecessary to check if `stackFolders` is nil before appending, because in Go, appending a nil slice is safe and does not cause a panic.
Applied to files:
pkg/generator/varfile/generator.go
📚 Learning: 2025-12-16T18:20:55.614Z
Learnt from: CR
Repo: cloudposse/atmos PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-16T18:20:55.614Z
Learning: Applies to **/*.go : All errors MUST be wrapped using static errors defined in errors/errors.go; use errors.Join for combining multiple errors; use fmt.Errorf with %w for adding string context; use error builder for complex errors; use errors.Is() for error checking; NEVER use dynamic errors directly
Applied to files:
pkg/generator/errors.goerrors/errors.go
📚 Learning: 2025-10-02T19:17:51.630Z
Learnt from: osterman
Repo: cloudposse/atmos PR: 1504
File: pkg/profiler/profiler.go:20-31
Timestamp: 2025-10-02T19:17:51.630Z
Learning: In pkg/profiler/profiler.go, profiler-specific errors (ErrUnsupportedProfileType, ErrStartCPUProfile, ErrStartTraceProfile, ErrCreateProfileFile) must remain local and cannot be moved to errors/errors.go due to an import cycle: pkg/profiler → errors → pkg/schema → pkg/profiler. This is a valid exception to the centralized errors policy.
Applied to files:
pkg/generator/errors.go
📚 Learning: 2025-11-24T17:35:37.209Z
Learnt from: CR
Repo: cloudposse/atmos PR: 0
File: .cursor/rules/atmos-rules.mdc:0-0
Timestamp: 2025-11-24T17:35:37.209Z
Learning: Applies to **/*.go : Follow Go's error handling idioms: use meaningful error messages, wrap errors with context using `fmt.Errorf("context: %w", err)`, and consider using custom error types for domain-specific errors
Applied to files:
pkg/generator/errors.go
📚 Learning: 2025-11-24T17:35:37.209Z
Learnt from: CR
Repo: cloudposse/atmos PR: 0
File: .cursor/rules/atmos-rules.mdc:0-0
Timestamp: 2025-11-24T17:35:37.209Z
Learning: Applies to **/*.go : Provide clear error messages to users, include troubleshooting hints when appropriate, and log detailed errors for debugging
Applied to files:
pkg/generator/errors.go
📚 Learning: 2025-12-13T06:10:13.688Z
Learnt from: osterman
Repo: cloudposse/atmos PR: 1686
File: errors/errors.go:184-203
Timestamp: 2025-12-13T06:10:13.688Z
Learning: cloudposse/atmos: For toolchain work, duplicate/unused error sentinels in errors/errors.go should be cleaned up in a separate refactor PR and not block feature PRs; canonical toolchain sentinels live under toolchain/registry with re-exports in toolchain/errors.go.
Applied to files:
pkg/generator/errors.goerrors/errors.go
📚 Learning: 2025-04-26T15:54:10.506Z
Learnt from: haitham911
Repo: cloudposse/atmos PR: 1195
File: internal/exec/terraform_clean.go:99-99
Timestamp: 2025-04-26T15:54:10.506Z
Learning: The error variable `ErrRelPath` is defined in `internal/exec/terraform_clean_util.go` and is used across files in the `exec` package, including in `terraform_clean.go`. This is part of an approach to standardize error handling in the codebase.
Applied to files:
pkg/generator/errors.gointernal/exec/terraform_generate_required_providers.goerrors/errors.go
📚 Learning: 2025-12-16T18:20:55.614Z
Learnt from: CR
Repo: cloudposse/atmos PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-16T18:20:55.614Z
Learning: Applies to **/*.go : Organize imports in three groups separated by blank lines, sorted alphabetically: 1) Go stdlib, 2) 3rd-party (NOT cloudposse/atmos), 3) Atmos packages; maintain aliases: cfg, log, u, errUtils
Applied to files:
pkg/generator/errors.gointernal/exec/terraform_utils.go
📚 Learning: 2025-04-04T02:03:23.676Z
Learnt from: aknysh
Repo: cloudposse/atmos PR: 1185
File: internal/exec/yaml_func_store.go:26-26
Timestamp: 2025-04-04T02:03:23.676Z
Learning: The Atmos codebase currently uses `log.Fatal` for error handling in multiple places. The maintainers are aware this isn't an ideal pattern (should only be used in main() or init() functions) and plan to address it comprehensively in a separate PR. CodeRabbit should not flag these issues or push for immediate changes until that refactoring is complete.
Applied to files:
pkg/generator/errors.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:
pkg/generator/errors.gointernal/exec/terraform.gointernal/exec/terraform_utils.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:
pkg/generator/errors.gointernal/exec/terraform_generate_required_providers.go
📚 Learning: 2024-11-18T13:59:10.824Z
Learnt from: aknysh
Repo: cloudposse/atmos PR: 768
File: internal/exec/vendor_model_component.go:3-20
Timestamp: 2024-11-18T13:59:10.824Z
Learning: When replacing significant dependencies like `go-getter` that require extensive changes, prefer to address them in separate PRs.
Applied to files:
pkg/generator/errors.go
📚 Learning: 2025-01-25T04:01:58.095Z
Learnt from: Listener430
Repo: cloudposse/atmos PR: 934
File: internal/exec/docs_generate.go:98-101
Timestamp: 2025-01-25T04:01:58.095Z
Learning: In the `generateSingleReadme` function of the docs generation feature (internal/exec/docs_generate.go), errors from `fetchAndParseYAML` should be logged and skipped rather than causing early returns. This is by design to process all inputs and collect all errors, instead of failing fast on the first error.
Applied to files:
pkg/generator/errors.gointernal/exec/terraform_generate_required_providers.go
📚 Learning: 2024-10-27T04:41:49.199Z
Learnt from: haitham911
Repo: cloudposse/atmos PR: 727
File: internal/exec/terraform_clean.go:215-223
Timestamp: 2024-10-27T04:41:49.199Z
Learning: In `internal/exec/terraform_clean.go`, the function `determineCleanPath` is necessary and should not be removed.
Applied to files:
internal/exec/terraform.gointernal/exec/terraform_generate_required_providers.gointernal/exec/terraform_utils.go
📚 Learning: 2024-11-02T15:35:09.958Z
Learnt from: aknysh
Repo: cloudposse/atmos PR: 759
File: internal/exec/terraform.go:366-368
Timestamp: 2024-11-02T15:35:09.958Z
Learning: In `internal/exec/terraform.go`, the workspace cleaning code under both the general execution path and within the `case "init":` block is intentionally duplicated because the code execution paths are different. The `.terraform/environment` file should be deleted before executing `terraform init` in both scenarios to ensure a clean state.
Applied to files:
internal/exec/terraform.gointernal/exec/terraform_generate_required_providers.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.go
📚 Learning: 2025-12-13T06:10:25.156Z
Learnt from: osterman
Repo: cloudposse/atmos PR: 1686
File: internal/exec/workflow_utils.go:0-0
Timestamp: 2025-12-13T06:10:25.156Z
Learning: Atmos workflows: In internal/exec/workflow_utils.go ExecuteWorkflow, non-identity steps intentionally use baseWorkflowEnv, which is constructed from the parent environment with PATH modifications for the toolchain. Avoid appending os.Environ() again; prefer documenting this behavior and testing that standard environment variables are preserved.
Applied to files:
internal/exec/terraform.go
📚 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.gointernal/exec/terraform_generate_required_providers.gointernal/exec/terraform_utils.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:
internal/exec/terraform.gointernal/exec/terraform_generate_required_providers.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/terraform.go
📚 Learning: 2025-12-13T03:21:35.786Z
Learnt from: osterman
Repo: cloudposse/atmos PR: 1813
File: cmd/terraform/shell.go:28-73
Timestamp: 2025-12-13T03:21:35.786Z
Learning: In Atmos, when calling cfg.InitCliConfig, you must first populate the schema.ConfigAndStacksInfo struct with global flag values using flags.ParseGlobalFlags(cmd, v) rather than passing an empty struct. The LoadConfig function (pkg/config/load.go) reads config selection fields (AtmosConfigFilesFromArg, AtmosConfigDirsFromArg, BasePath, ProfilesFromArg) directly from the ConfigAndStacksInfo struct, NOT from Viper. Passing an empty struct causes config selection flags (--base-path, --config, --config-path, --profile) to be silently ignored. Correct pattern: parse flags → populate struct → call InitCliConfig. See cmd/terraform/plan_diff.go for reference implementation.
Applied to files:
internal/exec/terraform.go
📚 Learning: 2025-12-13T04:37:25.223Z
Learnt from: osterman
Repo: cloudposse/atmos PR: 1686
File: cmd/root.go:0-0
Timestamp: 2025-12-13T04:37:25.223Z
Learning: In Atmos cmd/root.go Execute(), after cfg.InitCliConfig, we must call both toolchainCmd.SetAtmosConfig(&atmosConfig) and toolchain.SetAtmosConfig(&atmosConfig) so the CLI wrapper and the toolchain package receive configuration; missing either can cause nil-pointer panics in toolchain path resolution.
Applied to files:
internal/exec/terraform.gointernal/exec/terraform_utils.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:
internal/exec/terraform.gointernal/exec/terraform_utils.go
📚 Learning: 2025-12-16T18:20:55.614Z
Learnt from: CR
Repo: cloudposse/atmos PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-16T18:20:55.614Z
Learning: Applies to **/*.go : Use ATMOS_ prefix for environment variables with viper.BindEnv("ATMOS_VAR", "ATMOS_VAR", "FALLBACK")
Applied to files:
internal/exec/terraform.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:
internal/exec/terraform.gointernal/exec/terraform_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.gointernal/exec/terraform_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/terraform_generate_required_providers.go
📚 Learning: 2024-11-24T19:13:10.287Z
Learnt from: haitham911
Repo: cloudposse/atmos PR: 727
File: internal/exec/terraform_clean.go:407-416
Timestamp: 2024-11-24T19:13:10.287Z
Learning: In `internal/exec/terraform_clean.go`, when `getStackTerraformStateFolder` returns an error in the `handleCleanSubCommand` function, the error is logged, and the process continues without returning the error.
Applied to files:
internal/exec/terraform_generate_required_providers.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_generate_required_providers.go
📚 Learning: 2025-11-08T19:56:18.660Z
Learnt from: osterman
Repo: cloudposse/atmos PR: 1697
File: internal/exec/oci_utils.go:0-0
Timestamp: 2025-11-08T19:56:18.660Z
Learning: In the Atmos codebase, when a function receives an `*schema.AtmosConfiguration` parameter, it should read configuration values from `atmosConfig.Settings` fields rather than using direct `os.Getenv()` or `viper.GetString()` calls. The Atmos pattern is: viper.BindEnv in cmd/root.go binds environment variables → Viper unmarshals into atmosConfig.Settings via mapstructure → business logic reads from the Settings struct. This provides centralized config management, respects precedence, and enables testability. Example: `atmosConfig.Settings.AtmosGithubToken` instead of `os.Getenv("ATMOS_GITHUB_TOKEN")` in functions like `getGHCRAuth` in internal/exec/oci_utils.go.
Applied to files:
internal/exec/terraform_utils.go
📚 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/utils.go
📚 Learning: 2025-12-16T18:20:55.614Z
Learnt from: CR
Repo: cloudposse/atmos PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-16T18:20:55.614Z
Learning: New configs support Go templating with FuncMap() from internal/exec/template_funcs.go
Applied to files:
internal/exec/utils.go
📚 Learning: 2024-11-19T23:00:45.899Z
Learnt from: osterman
Repo: cloudposse/atmos PR: 795
File: internal/exec/stack_processor_utils.go:378-386
Timestamp: 2024-11-19T23:00:45.899Z
Learning: In the `ProcessYAMLConfigFile` function within `internal/exec/stack_processor_utils.go`, directory traversal in stack imports is acceptable and should not be restricted.
Applied to files:
internal/exec/utils.go
📚 Learning: 2025-10-08T06:48:07.499Z
Learnt from: aknysh
Repo: cloudposse/atmos PR: 1602
File: internal/exec/stack_processor_utils.go:968-1003
Timestamp: 2025-10-08T06:48:07.499Z
Learning: The `FindComponentDependenciesLegacy` function in `internal/exec/stack_processor_utils.go` is legacy code that is not actively used and is kept only for backward compatibility purposes.
Applied to files:
internal/exec/utils.go
🧬 Code graph analysis (4)
pkg/generator/errors.go (1)
errors/errors.go (9)
ErrGeneratorNotFound(312-312)ErrInvalidGeneratorCtx(313-313)ErrGeneratorValidation(314-314)ErrGenerationFailed(315-315)ErrGeneratorWriteFailed(316-316)ErrMissingWorkingDir(317-317)ErrComponentEmpty(299-299)ErrStackEmpty(300-300)ErrMissingProviderSource(318-318)
pkg/generator/generator.go (3)
pkg/generator/registry.go (1)
Generate(111-149)pkg/schema/schema.go (4)
Context(504-519)Validate(219-221)AtmosConfiguration(53-96)ConfigAndStacksInfo(646-749)pkg/generator/options.go (2)
Option(6-6)ApplyOptions(30-34)
pkg/generator/registry.go (4)
pkg/generator/generator.go (2)
Generator(22-39)GeneratorContext(42-88)pkg/logger/log.go (1)
Debug(24-26)pkg/generator/errors.go (4)
ErrGeneratorNotFound(13-13)ErrValidationFailed(19-19)ErrGenerationFailed(22-22)ErrWriteFailed(25-25)pkg/generator/writer.go (1)
Writer(11-16)
internal/exec/utils.go (1)
pkg/config/const.go (2)
RequiredProvidersSectionName(87-87)RequiredVersionSectionName(86-86)
⏰ Context from checks skipped due to timeout of 900000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
- GitHub Check: Acceptance Tests (windows)
- GitHub Check: Acceptance Tests (macos)
- GitHub Check: Summary
🔇 Additional comments (37)
internal/exec/terraform.go (1)
301-306: Clean integration of required_providers generation.Placement after
generateProviderOverridesis logical. Error handling is consistent with surrounding code. The DEV-3124 reference provides good traceability.internal/exec/utils.go (2)
100-118: Solid extraction logic with graceful fallback.The dual-type handling for
required_providers(lines 101-113) handles YAML unmarshaling variations well. One consideration: when a provider value isn't amap[string]any(line 106), it's silently skipped rather than logged. This is fine if malformed configs are caught by schema validation upstream.
1003-1016: Correct restoration after template processing.The restoration logic mirrors the extraction pattern, ensuring
RequiredProvidersandRequiredVersionare properly restored after Go templates and YAML functions are processed.pkg/generator/errors.go (1)
1-38: Re-export pattern properly uses centralized errors.This addresses the coding guidelines correctly. All errors are aliases to sentinels defined in
errors/errors.go, not independent definitions. The naming provides generator-specific context (e.g.,ErrMissingComponent→errUtils.ErrComponentEmpty) while maintaining the single source of truth.pkg/datafetcher/schema/stacks/stack-config/1.0.json (2)
1216-1258: Well-structured schema definitions.The
required_providersschema correctly:
- Validates provider names via
patternProperties- Requires
sourcefield (aligns with generator validation inpkg/generator/required_providers/generator.go)- Supports
!includepattern for consistency with other sectionsThe
required_versionschema is appropriately simple as a string constraint.
236-242: Consistent placement in terraform section.Refs added after
providers, maintaining logical grouping of provider-related configuration.errors/errors.go (3)
269-270: Required_providers error sentinels added.These align with the new extraction and validation paths in stack processing.
286-287: Override-specific error sentinels.Consistent pattern with other override errors in this section.
311-318: Generator error sentinels complete the framework.Good coverage: not found, invalid context, validation, generation, write failures, and specific missing fields. These are re-exported in
pkg/generator/errors.gofor package ergonomics.cmd/terraform/generate/generate.go (3)
3-7: Import organization looks good.The imports are correctly organized with the Cobra external dependency followed by internal Atmos packages. The blank line separator maintains proper grouping.
22-23: Documentation updated appropriately.The Long description now includes both
planfileandrequired-providerssubcommands. Clear and concise.
28-31: Solid command registration pattern.The init() approach for wiring the subcommand is consistent with Cobra patterns. The comment referencing DEV-3124 provides good traceability.
internal/exec/terraform_utils.go (3)
3-16: Imports organized correctly.Standard library first, then Atmos packages with proper aliases (cfg, log, u). Clean separation.
129-135: Smart early exit pattern.Skipping generation when neither
RequiredVersionnorRequiredProvidersare configured avoids unnecessary work. Solid defensive check.
141-150: Clean dry-run handling and generator integration.The dry-run check before file operations is correctly placed. The generator context and Generate call follow the new framework pattern established in this PR.
internal/exec/terraform_generate_required_providers.go (4)
3-15: Import structure follows guidelines.Three proper groups: stdlib, 3rd-party (Cobra), then Atmos packages with standard aliases (
cfg,rp,log).
20-25: Function entry point well-structured.Performance tracking with
nilconfig param follows guidelines. Argument validation is clear and direct.
71-85: File path resolution logic is solid.Handles both custom
--filepaths and defaults to the working directory with the default filename. Clean fallback pattern.
106-119: Custom filename handling addresses previous review concern.The logic correctly extracts the filename and updates
WorkingDirwhen a full path is specified. The checkdir != "." && dir != ""properly handles relative filenames vs absolute paths.pkg/generator/varfile/generator.go (3)
42-48: Nil check added per previous feedback.The guard for
genCtx == nilprevents potential panics. Good defensive programming.
64-82: Generate method is clean and focused.Validates first, handles the empty vars case gracefully by returning nil, and returns the VarsSection directly. The pattern is straightforward.
87-100: Nil checks appropriately address the safety concern.The added nil checks prevent panics and correctly handle missing context. Upstream validation in
GetContextPrefixensuresContextPrefixis never empty (it validates all context fields per the stack name pattern), andComponentis a required field in stack definitions. The current implementation is sound and doesn't require additional empty-value validation at this function level.pkg/generator/registry.go (4)
13-32: Thread-safe singleton pattern implemented correctly.The
sync.Onceensures single initialization, and the mutex protects concurrent access. Clean setup.
34-41: Registration pattern is sound.Using
gen.Name()as the key ensures generators self-identify. The debug log aids troubleshooting. MultipleGetRegistry()calls are fine sincesync.Oncecaches the result.
68-108: GenerateAll follows a clear lifecycle.The flow: check
ShouldGenerate→Validate→Generate→ write if content exists. Error wrapping with sentinel errors provides good context. The read lock during iteration is acceptable since registration only happens at init time.
110-149: Generate supports custom filenames.The fallback from
CustomFilenametoDefaultFilename()(lines 138-142) is clean. Error propagation with wrapped errors maintains debuggability.pkg/generator/required_providers/generator.go (7)
1-11: LGTM!Package declaration and imports are properly organized according to the coding guidelines (stdlib → 3rd-party → atmos packages, alphabetically sorted).
13-18: LGTM!Constants are well-defined with clear naming and appropriate visibility.
20-36: LGTM!The Generator struct, compile-time interface check, and registry registration follow the established pattern correctly.
38-46: LGTM!Simple getter methods with correct implementations.
48-54: LGTM!The conditional logic correctly determines whether generation should proceed, with proper nil guards.
56-74: LGTM!Validation logic is thorough, checking for nil context and ensuring all providers have the required
sourcefield. Error wrapping follows the guidelines correctly.
76-120: LGTM!The Generate method correctly builds the Terraform configuration structure with proper error handling and defensive checks. The output format matches the documented structure.
pkg/generator/generator.go (4)
1-9: LGTM!Package declaration and imports are properly organized.
11-19: LGTM!Format type and constants provide clear type safety for output format specification.
21-39: LGTM!The Generator interface is well-designed with clear separation of concerns and proper documentation following Go conventions.
41-88: LGTM!GeneratorContext is comprehensive and well-documented, providing all necessary context for file generation operations.
Implement DEV-3124 to allow pinning Terraform and provider versions per component using required_version and required_providers in stack configuration. Includes unified generator package, CLI command, and schema updates. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
- Add CustomFilename field to GeneratorContext to support custom output paths - Move generator sentinel errors to central errors/errors.go - Re-export errors in pkg/generator/errors.go for backward compatibility - Add nil checks to ShouldGenerate methods in all generators - Add nil check to ConstructFilename in varfile generator 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
Add defer perf.Track() calls to NewGeneratorContext and NewGeneratorContextWithOptions per coding guidelines requiring performance tracking on all public functions. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
Announces the new capability to pin Terraform and provider versions directly in stack configuration (DEV-3124). 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
f1ecf14 to
7a1236e
Compare
|
Warning Release Documentation RequiredThis PR is labeled
|
Add milestone for pinning Terraform and provider versions (DEV-3124) to the Migration initiative. Update progress from 60% to 65%. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
|
💥 This pull request now has conflicts. Could you fix it Erik Osterman (Cloud Posse) (@osterman)? 🙏 |
…provider-versions-of-components-using-terraform Resolved conflicts: - errors/errors.go: Keep both required_providers errors and provision error - internal/exec/stack_processor_process_stacks_helpers.go: Keep both required_providers fields and provision field - pkg/config/const.go: Keep both required_providers constants and provision constant 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
|
Tip Atmos Pro
No affected stacks workflow was detected for this pull request. |
Codecov Report❌ Patch coverage is ❌ Your patch check has failed because the patch coverage (77.90%) is below the target coverage (80.00%). You can increase the patch coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## main #1841 +/- ##
========================================
Coverage 78.07% 78.08%
========================================
Files 1100 1110 +10
Lines 104197 104674 +477
========================================
+ Hits 81348 81730 +382
- Misses 18344 18405 +61
- Partials 4505 4539 +34
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
Previously the entire file was at 0% patch coverage (60 missing lines). Add focused unit tests around the four functions whose logic can be exercised without the full atmos.yaml+stack fixture machinery: * parseRequiredProvidersFlags — all defaults, all flags set, optional --file flag missing (regression guard for the helper's intentional error swallow on `file`), and a missing required flag. * configureCustomFilePath — empty arg no-op, basename-only, ./prefix, absolute path with directory split, relative subdir split. * generateRequiredProvidersFile — short-circuits when neither required_version nor required_providers is set, and DryRun returns nil without invoking generator.Generate (with and without a custom file path). * ExecuteTerraformGenerateRequiredProvidersCmd — zero-args and too-many-args both surface ErrInvalidComponentArgument. Function-level coverage after: - parseRequiredProvidersFlags: 0% → 78.6% - configureCustomFilePath: 0% → 100% - generateRequiredProvidersFile: 0% → 90.9% - ExecuteTerraformGenerateRequiredProvidersCmd: 0% → 14.3% (full happy-path needs a real component on disk, deferred) Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Windows CI failed on TestConfigureCustomFilePath/absolute_path_splits_into_dir+basename because the test hard-coded "/tmp/generated" as the expected WorkingDir, but the production helper calls filepath.Dir which on Windows returns "\tmp\generated". The basename-only and ./prefix cases happened to pass because they have no directory component to normalize. Fix per CLAUDE.md path-handling guidance: * Input paths now flow through filepath.FromSlash so the same test source produces "/tmp/generated/custom.tf.json" on Unix and "\tmp\generated\custom.tf.json" on Windows. * Expected WorkingDir is computed via filepath.Dir(tt.fileFromArg) so both sides go through the same platform-aware separator handling. * originalWorkdir is built once via filepath.FromSlash so the "workdir unchanged" assertions match on Windows too. Drops the now-redundant wantWorkingDir field from the table — the expected value is fully derivable from fileFromArg via filepath.Dir. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
|
These changes were released in v1.218.0. |
…loudposse#2950) * fix(schema): model required_version/required_providers/retry and native Helm in atmos-manifest schema Fixes cloudposse#2948: `atmos validate stacks`/`atmos describe stacks` reject `required_version`, `required_providers`, and `retry` under `components.terraform.<name>` (and the shared `overrides` block) even though they're fully supported by the stack processor. The fields were added to the legacy, unenforced `stack-config` schema by cloudposse#1841 but never ported to `atmos-manifest`, the schema actually enforced by validate/describe — drift that stayed invisible until cloudposse#2749 fixed a separate bug that had been silently skipping schema validation by default. - Add `required_version`/`required_providers`/`retry` to the `terraform`, `terraform_component_manifest`, and `overrides` definitions. - Add `generate` to the stack-level `kubernetes` definition (same drift class, found auditing for other instances). - Model native Helm (`helm`, `helm_repository`, `helm_components`, `helm_component_manifest`), closing the tracked `topLevel:helm` gap in the schema-coverage guard. - Fix `schema_section_coverage_test.go`: `required_version`, `required_providers`, and `retry` were explicitly exempted from the coverage guard with the comment "introspected from Terraform, not authored" — factually wrong, since they're user-authored fields with full stack-processor support. This exemption is why the guard never caught the original gap; verified it now fails without the schema fix and passes with it. - Sync the same edits into the `tests/fixtures/schemas/...` copy and extend the `atmos-stacks-validation` fixture with real usage of all the fixed fields, so `TestValidateStacksCmd_Success` is a live regression guard for this bug class. Closes cloudposse#2948 * fix(schema): address CodeRabbit findings on PR cloudposse#2950 Verified each finding against the actual stack-processor code before applying (per CodeRabbit's own review instructions) rather than applying suggestions blindly: - Sync the native Helm definitions (helm, helm_repository, helm_components, helm_component_manifest, plus their plugins/ kubernetes_render dependencies) into the tests/fixtures/schemas/... copy, which lacked them entirely — valid, the fixture was silently permissive on Helm fields instead of validating them. - Add locals/command/secrets to helm_component_manifest and accept the `^!include` string form for `values` — verified all three sections are read unconditionally for every component type (internal/exec/stack_processor_process_stacks_helpers_extraction.go), not gated to specific types, so Helm components support them too. - Tighten required_providers' additionalProperties from true to false on both the provider map and each provider entry, matching the documented source/version/configuration_aliases contract, in both the canonical and fixture schema copies. Skipped one sub-claim: adding `locals`/`overrides` to the top-level `helm` type-defaults object. Neither is read from `globalHelmSection` in internal/exec/stack_processor_process_stacks.go, and the nested type-level `overrides:` mechanism (internal/exec/stack_processor_utils.go) only wires up terraform/helmfile, not helm/kubernetes/packer — adding them to the schema would validate configuration the stack processor silently ignores. * fix(test): stop schema-drift fixture from polluting shared mock component The stack-wide `terraform: { required_version, required_providers, retry, overrides }` block added to tests/fixtures/scenarios/atmos-stacks-validation cascaded into `component-1`, which internal/exec/terraform_test.go's TestExecuteTerraform_OpaValidation runs real `terraform plan`/`apply` against. Since that component has no JIT source-provisioning, Atmos's generateRequiredProviders step (invoked from the plan/apply pipeline) wrote a `terraform_override.tf.json` directly into the shared, checked-in tests/fixtures/components/terraform/mock/ directory instead of an isolated workdir — polluting every other test reusing that component for the rest of the CI run: - describe_component_with_stack_flag's golden snapshot picked up the leaked required_version/required_providers via tfconfig.LoadModule(). - atmos_vendor_pull#01/atmos_vendor_simple_exclude/ atmos_vendor_combined_exclude_include failed on a corrupted/incomplete shared hashicorp/time provider plugin-cache entry from the stray `terraform init` the leaked required_providers triggered. Remove the stack-wide block (component-level required_version/ required_providers/retry on the new, never-executed component-test-required-providers component is unaffected and stays). Add TestValidateStacksAcceptsRequiredProvidersRetryAndKubernetesGenerate to internal/exec/validate_stacks_test.go instead, covering stack-level terraform.required_version/required_providers/retry, the shared overrides definition, and kubernetes.generate via ValidateStacks only (schema validation, never ExecuteTerraform) in an isolated t.TempDir() -- carrying none of the pollution risk. Verified locally: ran TestExecuteTerraform_OpaValidation and confirmed no terraform_override.tf.json is written into the shared mock directory; re-ran the four previously-failing CI tests, all pass. * fix(schema): sync stack-level kubernetes route into the fixture schema CodeRabbit: the fixture root exposed no `kubernetes` property, so it could not enforce the `kubernetes.generate` contract exercised by TestValidateStacksAcceptsRequiredProvidersRetryAndKubernetesGenerate (that test currently validates via the default embedded schema, so it wasn't failing, but the fixture is meant to mirror the enforced schema per the project's established three-file sync pattern). Port the full kubernetes definition family from the canonical schema (kubernetes, kubernetes_provider, kubernetes_paths, kubernetes_manifest, kubernetes_manifests, kubernetes_components, kubernetes_component_manifest -- kubernetes_render was already added for native Helm's sake) and wire kubernetes into the fixture's root properties and components definition. Verified by validating stacks with an explicit kubernetes.generate block against this exact fixture file (schemas.atmos.manifest override), not just the embedded default. * fix(security): resolve CodeQL go/allocation-size-overflow alerts pkg/workflow/container.go's mergeEnvSlices sized two allocations off len(base)+len(overlay), the summed-len() capacity-hint pattern CodeQL flags as a potential overflow (alerts #5326-#5329). Size off len(base) instead, matching the established fix from 0e32451. Dependabot alerts cloudposse#275/cloudposse#276 (image-size, high severity, transitive via website/pnpm-lock.yaml) remain open: GitHub reports first_patched_version: null for both, and the npm registry confirms 2.0.2 (the currently-pinned version) is the latest published release. No fix exists upstream yet.
what
pkg/generatorpackage with registry pattern for Terraform file generationrequired_providersandrequired_versionsupport in stack configurationsatmos terraform generate required-providersCLI commandterraform_override.tf.jsonwith version constraints during terraform commandswhy
This feature allows users to pin Terraform and provider versions per component, improving reproducibility and reducing dependency-related issues. The unified generator package consolidates file generation logic for better maintainability.
references
Closes #3124
Summary by CodeRabbit
New Features
Documentation
✏️ Tip: You can customize this high-level summary in your review settings.