Update atmos.yaml config for Terraform/OpenTofu to enable passing the generated varfile to tofu init#1163
Update atmos.yaml config for Terraform/OpenTofu to enable passing the generated varfile to tofu init#1163
atmos.yaml config for Terraform/OpenTofu to enable passing the generated varfile to tofu init#1163Conversation
📝 WalkthroughWalkthroughThe changes introduce a new initialization configuration for Terraform components within Atmos. A new Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant CLIParser
participant ConfigProcessor
participant ExecuteTerraform
participant Terraform
User->>CLIParser: Provide CLI args (--init-pass-vars)
CLIParser->>ConfigProcessor: Parse CLI flags & ENV variables
ConfigProcessor->>ExecuteTerraform: Pass configuration (init.pass_vars flag)
ExecuteTerraform->>Terraform: Run 'terraform init' with --var-file if pass_vars enabled
Terraform-->>ExecuteTerraform: Return execution results
ExecuteTerraform-->>User: Output results
Possibly related PRs
📜 Recent review detailsConfiguration used: .coderabbit.yaml ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms (2)
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (2)
internal/exec/utils.go (1)
849-860: Initialize InitPassVars flag for command-line processingThe implementation follows the established pattern for flag processing in the codebase. However, it uses dynamic error creation which violates the static analysis rule.
Consider using wrapped static errors instead of dynamic errors:
- return info, fmt.Errorf("invalid flag: %s", arg) + return info, fmt.Errorf("%w: %s", ErrInvalidFlag, arg)This would require defining a new error variable like:
var ErrInvalidFlag = errors.New("invalid flag")🧰 Tools
🪛 GitHub Check: golangci-lint
[failure] 851-851:
do not define dynamic errors, use wrapped static errors instead: "fmt.Errorf("invalid flag: %s", arg)"
[failure] 857-857:
do not define dynamic errors, use wrapped static errors instead: "fmt.Errorf("invalid flag: %s", arg)"pkg/config/utils.go (1)
272-280: Added environment variable processing for InitPassVarsThe code properly handles the ATMOS_COMPONENTS_TERRAFORM_INIT_PASS_VARS environment variable, but uses deprecated logging function.
Replace the deprecated
u.LogDebugwithlog.Debug:- u.LogDebug(fmt.Sprintf("Found ENV var ATMOS_COMPONENTS_TERRAFORM_INIT_PASS_VARS=%s", componentsInitPassVars)) + log.Debug("Found ENV var", "ATMOS_COMPONENTS_TERRAFORM_INIT_PASS_VARS", componentsInitPassVars)🧰 Tools
🪛 GitHub Check: golangci-lint
[failure] 274-274:
SA1019: u.LogDebug is deprecated: Uselog.Debuginstead. This function will be removed in a future release. LogDebug logs the provided debug message
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
go.sumis excluded by!**/*.sum
📒 Files selected for processing (19)
atmos.yaml(1 hunks)cmd/list_components.go(1 hunks)cmd/list_stacks.go(1 hunks)go.mod(1 hunks)internal/exec/atmos.go(2 hunks)internal/exec/terraform.go(1 hunks)internal/exec/utils.go(2 hunks)pkg/config/const.go(1 hunks)pkg/config/default.go(2 hunks)pkg/config/utils.go(3 hunks)pkg/list/list_components_test.go(2 hunks)pkg/list/list_stacks_test.go(2 hunks)pkg/schema/schema.go(3 hunks)tests/fixtures/scenarios/atmos-configuration/atmos.d/tools/terraform.yaml(1 hunks)website/docs/cli/configuration/components.mdx(1 hunks)website/docs/cli/configuration/configuration.mdx(2 hunks)website/docs/core-concepts/projects/configuration/opentofu.mdx(1 hunks)website/docs/core-concepts/projects/configuration/terraform.mdx(3 hunks)website/docs/quick-start/advanced/configure-cli.mdx(1 hunks)
🧰 Additional context used
🧬 Code Definitions (4)
cmd/list_components.go (2)
internal/exec/describe_stacks.go (1) (1)
ExecuteDescribeStacks(148-687)pkg/describe/describe_stacks.go (1) (1)
ExecuteDescribeStacks(9-19)
pkg/config/default.go (1)
pkg/schema/schema.go (1) (1)
TerraformInit(261-263)
internal/exec/utils.go (5)
internal/exec/describe_component.go (1) (1)
configAndStacksInfo(106-106)internal/exec/aws_eks_update_kubeconfig.go (1) (1)
configAndStacksInfo(125-125)pkg/component/component_processor.go (2) (2)
configAndStacksInfo(19-19)configAndStacksInfo(55-55)pkg/config/const.go (1) (1)
InitPassVars(31-31)pkg/config/cache.go (1) (1)
cfg(54-54)
pkg/schema/schema.go (1)
pkg/config/const.go (2) (2)
InitRunReconfigure(30-30)InitPassVars(31-31)
🪛 GitHub Check: golangci-lint
pkg/config/utils.go
[failure] 274-274:
SA1019: u.LogDebug is deprecated: Use log.Debug instead. This function will be removed in a future release. LogDebug logs the provided debug message
internal/exec/utils.go
[failure] 851-851:
do not define dynamic errors, use wrapped static errors instead: "fmt.Errorf("invalid flag: %s", arg)"
[failure] 857-857:
do not define dynamic errors, use wrapped static errors instead: "fmt.Errorf("invalid flag: %s", arg)"
⏰ Context from checks skipped due to timeout of 90000ms (2)
- GitHub Check: Build (windows-latest, windows)
- GitHub Check: Summary
🔇 Additional comments (30)
go.mod (1)
53-53: Updated Dependency Version AnalysisThe dependency for
github.com/redis/go-redis/v9has been bumped from versionv9.7.1tov9.7.3. This minor version increment likely includes bug fixes and improvements. Please verify that this upgrade is compatible with existing usage within the codebase and confirm that there are no breaking changes introduced by this update.tests/fixtures/scenarios/atmos-configuration/atmos.d/tools/terraform.yaml (1)
24-26: Clean addition of the init.pass_vars configuration optionThe new configuration option adds support for passing variables during the Terraform/OpenTofu initialization phase. This directly implements the PR objective of enabling the passing of a generated varfile to the
tofu initcommand.The default value of
falseis appropriate for backward compatibility. The comment clearly explains how users can override this setting through environment variables or command-line arguments.website/docs/core-concepts/projects/configuration/opentofu.mdx (3)
32-53: Well-structured documentation with complete configuration exampleThe addition of a comprehensive YAML configuration example provides clear guidance on how to configure OpenTofu with Atmos. The format is consistent with the existing documentation style, and all configuration options are properly commented.
55-74: Thorough explanation of configuration optionsThe description list format effectively explains each configuration option, including the new
init.pass_varssetting. The documentation clearly states the purpose of each option and links to relevant external documentation for the OpenTofuinitcommand.
69-73: Clear documentation of the new featureThe explanation for
init.pass_varsis concise and informative. The reference to OpenTofu's documentation provides valuable context about the feature's purpose for dynamic backend configuration.pkg/config/const.go (1)
31-31: Appropriate constant definition for the new CLI flagThe new constant
InitPassVarsis correctly placed alongside other initialization-related flags. This follows the established pattern in the codebase for defining command-line arguments.pkg/config/default.go (2)
3-14: Cleaned up import statementsThe import statements have been consolidated to remove duplicate entries for the
errorsandviperpackages. This is a good practice that improves code readability.
42-44: Proper default configuration for the new featureThe addition of the
Initstruct withPassVarsset tofalseprovides a sensible default that maintains backward compatibility. This initialization properly configures the new feature and aligns with the YAML configuration defaults.cmd/list_components.go (1)
55-55: Added template and function processing.The parameters in the
ExecuteDescribeStackscall have been updated to enable both Go template processing and YAML function processing. This change aligns with the PR objective to fix the Atmos TUI for consistent template and function processing.cmd/list_stacks.go (1)
49-49: Enabled template and function processing consistently.Similar to the change in
list_components.go, the boolean parameters inExecuteDescribeStackshave been updated to enable Go template and YAML function processing. This ensures consistent behavior across all components that interact with stack configurations.internal/exec/atmos.go (2)
44-44: Enhanced TUI with template and function processing.The parameters in the
ExecuteDescribeStackscall have been updated to enable Go template and YAML function processing, matching the same changes made in other components. This ensures a consistent approach to processing stack manifests.
150-151: Added explicit template and function processing for Terraform commands.Setting both
ProcessTemplatesandProcessFunctionsto true ensures that Terraform commands process Go templates and YAML functions correctly in the Atmos TUI, fulfilling one of the key objectives of this PR.internal/exec/terraform.go (1)
369-373: Added support for passing varfile totofu init.This change implements the primary objective of the PR by adding logic to pass a variable file to the
initcommand when thePassVarsoption is enabled inatmos.yaml. OpenTofu supports this feature for dynamic backend configuration, which enhances flexibility in managing Terraform configurations.The implementation correctly uses the existing variable flag and file variables, maintaining consistency with other command implementations in the codebase.
website/docs/cli/configuration/components.mdx (1)
75-77: Documentation added for new Terraform init configurationThe addition of the
pass_varsconfiguration option under theinitsection is well-documented with clear comments explaining how to set it via environment variables or command-line arguments.website/docs/quick-start/advanced/configure-cli.mdx (1)
58-60: Documentation consistent with other filesThe
init.pass_varsconfiguration is consistently documented here, matching the implementation in the main configuration file.atmos.yaml (1)
44-46: New feature for passing vars to tofu initThis configuration addition implements the main PR objective - enabling the passing of generated varfiles to the
tofu initcommand. The default is appropriately set tofalseto maintain backward compatibility.pkg/list/list_components_test.go (2)
24-25: Updated test parameters to reflect new functionalityThe parameters for
ExecuteDescribeStackshave been updated to accommodate the new configuration option. This ensures the tests properly validate the new functionality.
44-45: Consistent parameter updates in multiple test functionsThe parameter changes maintain consistency across multiple test functions, ensuring all tests properly handle the new configuration option.
internal/exec/utils.go (1)
232-232: Correctly added InitPassVars field to configAndStacksInfo structureThe change propagates the InitPassVars setting from argsAndFlagsInfo to configAndStacksInfo, maintaining consistency with similar boolean flag handling patterns.
pkg/list/list_stacks_test.go (2)
21-21: Updated ExecuteDescribeStacks parameters to support template and function processingThe parameter values have been updated from all
falseto includetrue, true, falsewhich enables Go template processing and YAML function handling when describing stacks in tests.
37-37: Consistent update of ExecuteDescribeStacks parametersThe same parameter changes were applied here for consistency with line 21, ensuring both test functions use the same processing capabilities.
website/docs/core-concepts/projects/configuration/terraform.mdx (2)
10-10: Added link to Terraform websiteImproved documentation by adding a proper hyperlink to the Terraform website, enhancing user experience.
42-44: Added documentation for new init.pass_vars configuration optionClear documentation for the new capability to pass variables during initialization, including environment variable and command-line flag information.
pkg/config/utils.go (1)
514-521: Added command-line argument processing for InitPassVarsThe implementation properly handles the InitPassVars command-line argument, following the same pattern used for other boolean flags.
pkg/schema/schema.go (4)
258-259: New field for OpenTofu's variable passing feature.The addition of
Initfield to theTerraformstruct enables configuration for passing variables during initialization, which is supported by OpenTofu. Good placement and consistent tagging with the rest of the struct.
261-263: Well-structured new configuration struct.Clean implementation of the
TerraformInitstruct with a boolean fieldPassVarsthat controls whether to pass generated variable files to thetofu initcommand. The struct follows the code style and tag patterns established in the codebase.
344-344: Added field for CLI argument handling.The
InitPassVarsfield inArgsAndFlagsInfostruct will store information related to command-line arguments for the init pass vars feature. This aligns with how other CLI arguments are handled in the codebase.
403-403: Added field for component configuration info.The
InitPassVarsfield inConfigAndStacksInfostruct will track the initialization variables configuration for use in command execution. This follows the established pattern for handling component configuration.website/docs/cli/configuration/configuration.mdx (2)
60-61: Documentation for new configuration option.Good addition of the
initsection withpass_vars: falseto the default CLI configuration. The default value offalsemaintains backward compatibility for existing users.
697-697: Clear documentation for environment variable.Well-documented environment variable with a descriptive comment explaining its purpose and linking to the OpenTofu documentation. This helps users understand how to use this feature for dynamic backend configuration.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1163 +/- ##
==========================================
+ Coverage 25.87% 26.88% +1.01%
==========================================
Files 180 180
Lines 20627 20662 +35
==========================================
+ Hits 5337 5556 +219
+ Misses 14443 14177 -266
- Partials 847 929 +82
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Actionable comments posted: 1
♻️ Duplicate comments (1)
internal/exec/utils.go (1)
850-861:⚠️ Potential issueDo not define dynamic errors, use wrapped static errors instead.
The error handling in this block uses dynamic error messages which was previously flagged in code scanning.
Instead of:
return info, fmt.Errorf("invalid flag: %s", arg)Consider using wrapped static errors:
-return info, fmt.Errorf("invalid flag: %s", arg) +var ErrInvalidFlag = errors.New("invalid flag") +return info, fmt.Errorf("%w: %s", ErrInvalidFlag, arg)This pattern should be applied at both lines 852 and 858.
🧹 Nitpick comments (8)
internal/exec/utils.go (1)
850-861: Consider refactoring repetitive flag handling patterns.The flag handling code follows a highly repetitive pattern throughout the function. Consider refactoring this into a helper function to reduce duplication and make future additions easier.
+// processFlag is a helper function to process command line flags +func processFlag(flag string, args []string, index int) (string, int, error) { + if index+1 >= len(args) { + return "", index, fmt.Errorf("invalid flag: %s", flag) + } + return args[index+1], index + 1, nil +} + +// processFlagWithEquals is a helper function to process command line flags with equals +func processFlagWithEquals(arg string, flag string) (string, error) { + parts := strings.Split(arg, "=") + if len(parts) != 2 { + return "", fmt.Errorf("invalid flag: %s", arg) + } + return parts[1], nil +}Then simplify the flag handling:
-if arg == cfg.InitPassVars { - if len(inputArgsAndFlags) <= (i + 1) { - return info, fmt.Errorf("invalid flag: %s", arg) - } - info.InitPassVars = inputArgsAndFlags[i+1] -} else if strings.HasPrefix(arg+"=", cfg.InitPassVars) { - initPassVarsParts := strings.Split(arg, "=") - if len(initPassVarsParts) != 2 { - return info, fmt.Errorf("invalid flag: %s", arg) - } - info.InitPassVars = initPassVarsParts[1] -} +if arg == cfg.InitPassVars { + val, _, err := processFlag(arg, inputArgsAndFlags, i) + if err != nil { + return info, err + } + info.InitPassVars = val +} else if strings.HasPrefix(arg+"=", cfg.InitPassVars) { + val, err := processFlagWithEquals(arg, cfg.InitPassVars) + if err != nil { + return info, err + } + info.InitPassVars = val +}internal/exec/template_funcs_component.go (1)
82-92: Conditional logging based on component type.The updated logging logic now only logs Terraform outputs when the component is actually of Terraform type, which is more precise and prevents misleading log entries.
Consider updating the deprecated logging functions as highlighted by static analysis:
-u.LogTrace(fmt.Sprintf("Executed template function 'atmos.Component(%s, %s)'", component, stack)) +log.Debug(fmt.Sprintf("Executed template function 'atmos.Component(%s, %s)'", component, stack)) -u.LogTrace("'outputs' section:") +log.Debug("'outputs' section:") -u.LogError(err2) +log.Error(err2) -u.LogTrace(y) +log.Debug(y)🧰 Tools
🪛 GitHub Check: golangci-lint
[failure] 82-82:
SA1019: u.LogTrace is deprecated: Uselog.Debuginstead. This function will be removed in a future release. LogTrace logs the provided trace message
[failure] 85-85:
SA1019: u.LogTrace is deprecated: Uselog.Debuginstead. This function will be removed in a future release. LogTrace logs the provided trace message
[failure] 88-88:
SA1019: u.LogError is deprecated: Uselog.Errorinstead. This function will be removed in a future release. LogError logs errors to std.Error
[failure] 90-90:
SA1019: u.LogTrace is deprecated: Uselog.Debuginstead. This function will be removed in a future release. LogTrace logs the provided trace messageinternal/exec/template_funcs.go (3)
19-26: Optimize parameter passing by using pointers for large structsThe static analysis tool correctly points out that both
atmosConfigandconfigAndStacksInfoare large structs (5736 bytes and 1136 bytes respectively). For better performance, pass these by pointer rather than by value to avoid unnecessary copying.func FuncMap( - atmosConfig schema.AtmosConfiguration, - configAndStacksInfo schema.ConfigAndStacksInfo, + atmosConfig *schema.AtmosConfiguration, + configAndStacksInfo *schema.ConfigAndStacksInfo, ctx context.Context, gomplateData *data.Data, ) template.FuncMap {🧰 Tools
🪛 GitHub Check: golangci-lint
[failure] 20-20:
hugeParam: atmosConfig is heavy (5736 bytes); consider passing it by pointer
[failure] 21-21:
hugeParam: configAndStacksInfo is heavy (1136 bytes); consider passing it by pointer
32-37: Update the AtmosFuncs struct to use pointers for large structsThe
AtmosFuncsstruct is storing copies of the large structs. Update it to store pointers to these structs to align with the suggested function signature change.type AtmosFuncs struct { - atmosConfig schema.AtmosConfiguration - configAndStacksInfo schema.ConfigAndStacksInfo + atmosConfig *schema.AtmosConfiguration + configAndStacksInfo *schema.ConfigAndStacksInfo ctx context.Context gomplateData *data.Data }
39-41: Update Component method to match the pointer-based struct fieldsIf you implement the suggested changes for using pointers, update this method to match. Also, verify that
componentFuncis updated to accept pointers to these structs.func (f AtmosFuncs) Component(component string, stack string) (any, error) { - return componentFunc(f.atmosConfig, f.configAndStacksInfo, component, stack) + return componentFunc(*f.atmosConfig, *f.configAndStacksInfo, component, stack) }Alternatively, if
componentFuncis updated to accept pointers:func (f AtmosFuncs) Component(component string, stack string) (any, error) { - return componentFunc(f.atmosConfig, f.configAndStacksInfo, component, stack) + return componentFunc(f.atmosConfig, f.configAndStacksInfo, component, stack) }internal/exec/template_utils.go (3)
34-34: Update the call to FuncMap to match the suggested signature changeIf you implement the pointer-based parameter passing in
FuncMap, update this call to pass pointers to the structs.- funcs := lo.Assign(gomplate.CreateFuncs(ctx, &d), sprig.FuncMap(), FuncMap(schema.AtmosConfiguration{}, schema.ConfigAndStacksInfo{}, ctx, &d)) + config := &schema.AtmosConfiguration{} + stacksInfo := &schema.ConfigAndStacksInfo{} + funcs := lo.Assign(gomplate.CreateFuncs(ctx, &d), sprig.FuncMap(), FuncMap(config, stacksInfo, ctx, &d))
64-72: Optimize parameter passing in ProcessTmplWithDatasources by using pointersSimilar to the previous recommendation, use pointers for large struct parameters in this function signature.
func ProcessTmplWithDatasources( - atmosConfig schema.AtmosConfiguration, - configAndStacksInfo schema.ConfigAndStacksInfo, + atmosConfig *schema.AtmosConfiguration, + configAndStacksInfo *schema.ConfigAndStacksInfo, settingsSection schema.Settings, tmplName string, tmplValue string, tmplData any, ignoreMissingTemplateValues bool, ) (string, error) {Update the subsequent code to dereference the pointers where necessary, for example:
- if !atmosConfig.Templates.Settings.Enabled { + if !atmosConfig.Templates.Settings.Enabled {🧰 Tools
🪛 GitHub Check: golangci-lint
[failure] 66-66:
hugeParam: configAndStacksInfo is heavy (1136 bytes); consider passing it by pointer
148-150: Update the call to FuncMap to match the suggested signature changeIf you implement the pointer-based parameter passing in
FuncMap, update this call accordingly.- funcs = lo.Assign(funcs, FuncMap(atmosConfig, configAndStacksInfo, context.TODO(), &d)) + funcs = lo.Assign(funcs, FuncMap(&atmosConfig, &configAndStacksInfo, context.TODO(), &d))
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (8)
internal/exec/describe_stacks.go(2 hunks)internal/exec/template_funcs.go(1 hunks)internal/exec/template_funcs_component.go(2 hunks)internal/exec/template_utils.go(3 hunks)internal/exec/terraform_generate_backends.go(1 hunks)internal/exec/terraform_generate_varfiles.go(1 hunks)internal/exec/utils.go(3 hunks)pkg/config/const.go(2 hunks)
🧰 Additional context used
🧬 Code Definitions (7)
internal/exec/describe_stacks.go (4)
internal/exec/utils.go (1) (1)
configAndStacksInfo(197-197)internal/exec/describe_component.go (1) (1)
configAndStacksInfo(106-106)internal/exec/aws_eks_update_kubeconfig.go (1) (1)
configAndStacksInfo(125-125)pkg/component/component_processor.go (2) (2)
configAndStacksInfo(19-19)configAndStacksInfo(55-55)
internal/exec/terraform_generate_varfiles.go (4)
internal/exec/utils.go (1) (1)
configAndStacksInfo(197-197)internal/exec/aws_eks_update_kubeconfig.go (1) (1)
configAndStacksInfo(125-125)pkg/component/component_processor.go (2) (2)
configAndStacksInfo(19-19)configAndStacksInfo(55-55)internal/exec/describe_component.go (1) (1)
configAndStacksInfo(106-106)
internal/exec/terraform_generate_backends.go (4)
internal/exec/utils.go (1) (1)
configAndStacksInfo(197-197)internal/exec/aws_eks_update_kubeconfig.go (1) (1)
configAndStacksInfo(125-125)pkg/component/component_processor.go (2) (2)
configAndStacksInfo(19-19)configAndStacksInfo(55-55)internal/exec/describe_component.go (1) (1)
configAndStacksInfo(106-106)
internal/exec/template_funcs_component.go (5)
pkg/schema/schema.go (3) (3)
AtmosConfiguration(13-45)ConfigAndStacksInfo(363-431)Logs(296-299)internal/exec/utils.go (1) (1)
configAndStacksInfo(197-197)internal/exec/describe_component.go (1) (1)
configAndStacksInfo(106-106)pkg/config/const.go (1) (1)
TerraformComponentType(42-42)internal/exec/terraform_outputs.go (2) (2)
err(70-70)execTerraformOutput(61-265)
internal/exec/template_funcs.go (6)
internal/exec/aws_eks_update_kubeconfig.go (2) (2)
atmosConfig(126-126)configAndStacksInfo(125-125)pkg/schema/schema.go (3) (3)
AtmosConfiguration(13-45)ConfigAndStacksInfo(363-431)Context(301-315)internal/exec/utils.go (1) (1)
configAndStacksInfo(197-197)internal/exec/describe_component.go (1) (1)
configAndStacksInfo(106-106)pkg/component/component_processor.go (2) (2)
configAndStacksInfo(19-19)configAndStacksInfo(55-55)internal/exec/template_funcs_component.go (1) (1)
componentFunc(16-96)
internal/exec/template_utils.go (2)
internal/exec/template_funcs.go (1) (1)
FuncMap(19-30)pkg/schema/schema.go (2) (2)
AtmosConfiguration(13-45)ConfigAndStacksInfo(363-431)
internal/exec/utils.go (5)
internal/exec/describe_component.go (1) (1)
configAndStacksInfo(106-106)internal/exec/aws_eks_update_kubeconfig.go (1) (1)
configAndStacksInfo(125-125)pkg/component/component_processor.go (2) (2)
configAndStacksInfo(19-19)configAndStacksInfo(55-55)pkg/config/const.go (1) (1)
InitPassVars(31-31)pkg/config/cache.go (1) (1)
cfg(54-54)
🪛 GitHub Check: golangci-lint
internal/exec/template_funcs_component.go
[failure] 16-16:
cognitive complexity 28 of func componentFunc is high (> 20)
[failure] 17-17:
hugeParam: atmosConfig is heavy (5736 bytes); consider passing it by pointer
[failure] 18-18:
hugeParam: configAndStacksInfo is heavy (1136 bytes); consider passing it by pointer
[warning] 53-53:
if configAndStacksInfo.ComponentType == cfg.TerraformComponentType has complex nested blocks (complexity: 5)
[failure] 82-82:
SA1019: u.LogTrace is deprecated: Use log.Debug instead. This function will be removed in a future release. LogTrace logs the provided trace message
[failure] 85-85:
SA1019: u.LogTrace is deprecated: Use log.Debug instead. This function will be removed in a future release. LogTrace logs the provided trace message
[failure] 88-88:
SA1019: u.LogError is deprecated: Use log.Error instead. This function will be removed in a future release. LogError logs errors to std.Error
[failure] 90-90:
SA1019: u.LogTrace is deprecated: Use log.Debug instead. This function will be removed in a future release. LogTrace logs the provided trace message
internal/exec/template_funcs.go
[failure] 20-20:
hugeParam: atmosConfig is heavy (5736 bytes); consider passing it by pointer
[failure] 21-21:
hugeParam: configAndStacksInfo is heavy (1136 bytes); consider passing it by pointer
internal/exec/template_utils.go
[failure] 66-66:
hugeParam: configAndStacksInfo is heavy (1136 bytes); consider passing it by pointer
⏰ Context from checks skipped due to timeout of 90000ms (2)
- GitHub Check: Build (windows-latest, windows)
- GitHub Check: Summary
🔇 Additional comments (9)
pkg/config/const.go (2)
31-31: New constant added for passing variables during initialization.The
InitPassVarsconstant is properly defined to support the new feature that enables passing a generated varfile to thetofu initcommand.
42-43: Component type constants improve code clarity.Moving from string literals to named constants for component types improves code readability and maintainability. This is a good practice that reduces the risk of typos when referencing these types elsewhere in the codebase.
internal/exec/utils.go (2)
232-232: ConfigAndStacksInfo struct updated with new InitPassVars field.The addition of the InitPassVars field to the configAndStacksInfo struct ensures that the new configuration option is properly propagated through the system.
515-515: Parameter passing updated in ProcessTmplWithDatasources.The line change appears to maintain the correct behavior while supporting the new initialization parameters for template processing.
internal/exec/describe_stacks.go (2)
379-379: Consistent implementation for template processing.Adding
configAndStacksInfoto theProcessTmplWithDatasourcescall provides access to additional context that ensures the template has access to component and stack metadata during processing.
581-581: Consistent parameter pattern across function calls.The addition of
configAndStacksInfohere maintains consistency with the previous change at line 379. This ensures both template processing calls for terraform and helmfile components have access to the same context information.internal/exec/terraform_generate_varfiles.go (1)
250-250: Making template processing consistent with other functions.Adding
configAndStacksInfotoProcessTmplWithDatasourcesensures that variable file generation has access to the same stack and component information as other template operations. This change aligns with the PR objective to enable passing the generated varfile totofu init.internal/exec/terraform_generate_backends.go (1)
241-241: Maintaining consistency in template processing.Adding
configAndStacksInfoto the function call provides access to additional context for backend configuration generation, which is essential for the PR objective of enabling varfile passing during initialization.internal/exec/template_funcs_component.go (1)
51-76: Improved conditional handling of Terraform remote state.This refactoring adds proper component type checking before processing Terraform remote state, ensuring that the operations are only performed for Terraform components. The structural change also improves code organization by:
- First checking for static remote state configuration
- Falling back to executing
terraform outputif needed- Properly handling the outputs in both cases
This change directly supports the PR objective by refining how component information is processed during initialization.
🧰 Tools
🪛 GitHub Check: golangci-lint
[warning] 53-53:
if configAndStacksInfo.ComponentType == cfg.TerraformComponentTypehas complex nested blocks (complexity: 5)
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (4)
internal/exec/template_funcs_component_test.go (4)
26-38: Consider using relative paths based on workDir for cleanup operations.The current cleanup uses hardcoded paths. It would be more maintainable to construct these paths relative to the
workDirvariable defined later in the test.defer func() { // Delete the generated files and folders after the test - err := os.RemoveAll(filepath.Join("components", "terraform", "mock", ".terraform")) + err := os.RemoveAll(filepath.Join(workDir, "components", "terraform", "mock", ".terraform")) assert.NoError(t, err) - err = os.RemoveAll(filepath.Join("components", "terraform", "mock", "terraform.tfstate.d")) + err = os.RemoveAll(filepath.Join(workDir, "components", "terraform", "mock", "terraform.tfstate.d")) assert.NoError(t, err)
57-60: Consider mocking ExecuteTerraform for more isolated testing.Directly calling
ExecuteTerraformcreates a dependency that may cause the test to fail for reasons unrelated to thecomponentFuncfunctionality you're testing. Consider creating a mock version for testing purposes.
70-74: Add more comprehensive assertions.The current assertions check only three specific values. Consider adding more assertions to validate the complete structure and all expected values of the component configuration to ensure thorough test coverage.
For example:
assert.Contains(t, y, "foo: component-1-a") assert.Contains(t, y, "bar: component-1-b") assert.Contains(t, y, "baz: component-1-b--component-1-c") +// Add assertions for other expected configuration values +assert.Contains(t, y, "expected_key: expected_value") +// Consider asserting the absence of values that shouldn't be there +assert.NotContains(t, y, "unexpected_key:")
16-16: Add more descriptive test documentation.Consider adding a brief comment before the test function explaining what specifically this test is verifying, especially how it relates to the new feature of passing varfiles to
tofu init.+// TestComponentFunc verifies that component functions correctly process and render component +// configurations, particularly focusing on the ability to pass variables to tofu/terraform commands +// as part of the PR enhancement to enable passing of generated varfiles to tofu init func TestComponentFunc(t *testing.T) {
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
internal/exec/template_funcs_component_test.go(1 hunks)
🧰 Additional context used
🧠 Learnings (1)
internal/exec/template_funcs_component_test.go (2)
Learnt from: samtholiya
PR: cloudposse/atmos#1077
File: pkg/downloader/custom_github_detector.go:0-0
Timestamp: 2025-03-20T16:30:34.659Z
Learning: The `github.com/charmbracelet/log` package should be imported with the alias `log` according to the project's import alias configuration.
Learnt from: samtholiya
PR: cloudposse/atmos#1077
File: pkg/downloader/custom_github_detector_test.go:0-0
Timestamp: 2025-03-20T16:30:44.601Z
Learning: The `github.com/charmbracelet/log` package should be imported with the alias `log`, not `clog`.
⏰ Context from checks skipped due to timeout of 90000ms (2)
- GitHub Check: Build (windows-latest, windows)
- GitHub Check: Summary
🔇 Additional comments (2)
internal/exec/template_funcs_component_test.go (2)
1-14: LGTM on imports and package declaration.The import statement using
log "github.com/charmbracelet/log"follows the project's aliasing conventions correctly.
16-25: Well-structured test setup.The test function includes proper logging configuration and working directory tracking. Good practice to capture the starting working directory to ensure tests are isolated and don't impact the environment.
|
These changes were released in v1.167.0. |
what
atmos.yamlconfig for Terraform/OpenTofu to enable passing the generatedvarfiletotofu initatmoscommand) to always processGotemplates and Atmos YAML functionsatmos.Componenttemplate functionwhy
varfiletoinitusing the-var-fileflag to dynamically configure backends. Allow enabling/disabling it inatmos.yamlWith this configuration, executing
atmos terraform init component-1 -s nonprodwill pass the generated varfile to theinitcommand:Fix Atmos TUI (launched using
atmoscommand) to always processGotemplates and Atmos YAML functions. This is in addition to the changes in this PR Add CLI flags toatmos terraformcommands to control processing the templates and YAML functions in Atmos stack manifests #1157Update
atmos.Componenttemplate functionreferences
Summary by CodeRabbit
New Features
Documentation