Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

expose env variable ATMOS_CLI_CONFIG_PATH and ATMOS_BASE_PATH before running terraform and helm cmd #1072

Merged
merged 4 commits into from
Feb 17, 2025

Conversation

haitham911
Copy link
Collaborator

@haitham911 haitham911 commented Feb 17, 2025

What

  • expose env variable ATMOS_CLI_CONFIG_PATH and ATMOS_BASE_PATH before running terraform and helm cmd

image

Why

  • Atmos should set the ATMOS_CLI_CONFIG_PATH , ATMOS_BASE_PATH

references

Summary by CodeRabbit

  • New Features

    • Enhanced deployment workflows with automated assignment of key configuration paths and environment variables.
    • Introduced dedicated configurations for multiple deployment stages (development, staging, and production) to streamline operations.
    • Updated Terraform settings now report essential environment variables for improved operational clarity.
    • New CLI configuration path added to improve management of environment settings.
  • Tests

    • Added automated test scenarios to verify accurate export and management of configuration settings during deployment.

@haitham911 haitham911 requested review from a team as code owners February 17, 2025 18:06
@mergify mergify bot added the triage Needs triage label Feb 17, 2025
Copy link
Contributor

coderabbitai bot commented Feb 17, 2025

📝 Walkthrough

Walkthrough

This pull request introduces enhancements to environment configuration handling across various components. The ExecuteHelmfile and ExecuteTerraform functions now include two new environment variables (ATMOS_CLI_CONFIG_PATH and ATMOS_BASE_PATH). The initialization of the CLI configuration has been improved to ensure that the configuration file path is absolute. Additionally, the AtmosConfiguration schema has been extended with a new field. New Terraform configuration and YAML files have been created to define deployment environments, alongside a new integration test to validate these changes.

Changes

File(s) Change Summary
internal/exec/helmfile.go, internal/exec/terraform.go Append ATMOS_CLI_CONFIG_PATH and ATMOS_BASE_PATH to the environment variable lists in ExecuteHelmfile and ExecuteTerraform functions.
pkg/config/config.go Introduce variable atmosConfigFilePath to capture and convert the configuration file path to an absolute path, assigning it to atmosConfig.CliConfigPath.
pkg/schema/schema.go Add new field CliConfigPath to the AtmosConfiguration struct and adjust spacing for the Stores field.
tests/fixtures/components/terraform/env-example/main.tf, tests/fixtures/components/terraform/env-example/outputs.tf Add Terraform provider declaration, a data block for filtering environment variables, new output variables for CLI config paths, and a stage variable.
tests/fixtures/scenarios/env/**/*.yaml Create new YAML configuration files (atmos.yaml, catalog entries, and deploy files for dev, prod, and staging) for environment deployment configurations.
tests/test-cases/env.yaml Add new test case atmos_terraform_apply_env to validate the export of atmos_base_path and atmos_cli_config_path during Terraform apply execution.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant AtmosCLI
    participant ConfigLoader
    participant HelmfileExec

    User->>AtmosCLI: Run helmfile command
    AtmosCLI->>ConfigLoader: Load configuration
    ConfigLoader-->>AtmosCLI: Return CLI config paths
    AtmosCLI->>HelmfileExec: Execute helmfile with env vars (ATMOS_CLI_CONFIG_PATH, ATMOS_BASE_PATH)
    HelmfileExec-->>AtmosCLI: Return command output
    AtmosCLI-->>User: Output result
Loading
sequenceDiagram
    participant User
    participant AtmosCLI
    participant ConfigLoader
    participant TerraformExec

    User->>AtmosCLI: Run terraform apply command
    AtmosCLI->>ConfigLoader: Load configuration
    ConfigLoader-->>AtmosCLI: Return CLI config paths
    AtmosCLI->>TerraformExec: Execute terraform with env vars (ATMOS_CLI_CONFIG_PATH, ATMOS_BASE_PATH)
    TerraformExec-->>AtmosCLI: Return execution output
    AtmosCLI-->>User: Output result
Loading

Possibly related PRs

  • Update YAML function !terraform.output #1048: The changes in the main PR, which involve adding environment variables to the ExecuteHelmfile function, are related to the modifications in the retrieved PR that enhance the handling of environment variables in the execTerraformOutput function.
  • Export configuration information in shell launched by Atmos #827: The changes in the main PR, which involve adding environment variables in the ExecuteHelmfile function, are related to the modifications in the retrieved PR that also add environment variables in the execTerraformShellCommand function.

Suggested labels

minor

Suggested reviewers

  • osterman
  • mcalhoun
  • aknysh

📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c1f10a5 and 292f5bf.

📒 Files selected for processing (1)
  • tests/fixtures/scenarios/env/stacks/catalog/example.yaml (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/fixtures/scenarios/env/stacks/catalog/example.yaml
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Build (windows-latest, windows)
  • GitHub Check: Analyze (go)
  • GitHub Check: Summary

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary or @auto-summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai or @auto-title anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
tests/fixtures/components/terraform/env-example/outputs.tf (1)

22-26: Variable Declaration for Deployment Stage.

The stage variable is clearly declared. As a suggestion for maintainability, consider moving variable declarations to a dedicated variables file (e.g., variables.tf) if this module expands.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 034e806 and ae5d6e0.

📒 Files selected for processing (12)
  • internal/exec/helmfile.go (1 hunks)
  • internal/exec/terraform.go (1 hunks)
  • pkg/config/config.go (7 hunks)
  • pkg/schema/schema.go (1 hunks)
  • tests/fixtures/components/terraform/env-example/main.tf (1 hunks)
  • tests/fixtures/components/terraform/env-example/outputs.tf (1 hunks)
  • tests/fixtures/scenarios/env/atmos.yaml (1 hunks)
  • tests/fixtures/scenarios/env/stacks/catalog/example.yaml (1 hunks)
  • tests/fixtures/scenarios/env/stacks/deploy/dev.yaml (1 hunks)
  • tests/fixtures/scenarios/env/stacks/deploy/prod.yaml (1 hunks)
  • tests/fixtures/scenarios/env/stacks/deploy/staging.yaml (1 hunks)
  • tests/test-cases/env.yaml (1 hunks)
✅ Files skipped from review due to trivial changes (3)
  • tests/fixtures/scenarios/env/stacks/catalog/example.yaml
  • tests/fixtures/scenarios/env/stacks/deploy/prod.yaml
  • tests/fixtures/scenarios/env/stacks/deploy/dev.yaml
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Build (windows-latest, windows)
  • GitHub Check: Summary
🔇 Additional comments (19)
internal/exec/helmfile.go (1)

243-244: LGTM! Environment variables added at the right location.

The environment variables ATMOS_CLI_CONFIG_PATH and ATMOS_BASE_PATH are correctly added to the envVars slice just before executing the helmfile command.

pkg/config/config.go (1)

142-142: LGTM! Robust implementation of config path tracking and handling.

The changes properly track the config file path and ensure it's converted to an absolute path before storing in atmosConfig.CliConfigPath. The implementation:

  • Tracks the path through all possible config locations
  • Handles both absolute and relative paths
  • Includes proper error handling

Also applies to: 164-164, 180-180, 195-195, 209-209, 224-224, 265-273

internal/exec/terraform.go (1)

225-226: LGTM! Environment variables added consistently with helmfile implementation.

The environment variables ATMOS_CLI_CONFIG_PATH and ATMOS_BASE_PATH are correctly added to info.ComponentEnvList before executing the terraform command, maintaining consistency with the helmfile implementation.

pkg/schema/schema.go (1)

39-40: LGTM! Clean addition of CliConfigPath field.

The CliConfigPath field is properly added to the AtmosConfiguration struct with consistent formatting and appropriate serialization tags.

tests/fixtures/scenarios/env/stacks/deploy/staging.yaml (4)

1-2: Schema Declaration is on point.

The YAML schema directive is correctly specified to aid language server validation for Atmos manifests.


3-5: Vars Block Clarity.

The vars section sets stage to "staging" clearly—just ensure that this aligns with your deployment pipeline expectations.


6-8: Import Directive Verified.

The import of catalog/example is straightforward. Double-check that the referenced catalog exists and contains the expected components.


9-12: Component Configuration Looks Solid.

The components section properly defines the Terraform component env-example with an empty vars block, serving as an extensible base.

tests/fixtures/components/terraform/env-example/main.tf (2)

1-8: Terraform Provider Block is Well Defined.

The provider declaration for environment uses the correct source and version constraint—with a reminder in the comment to check for the latest version, which is good practice.


10-13: Data Block for Environment Variables.

The data block efficiently captures environment variables matching the regex pattern "^ATMOS_.*|^EXAMPLE$". This filtering is clear and concise.

tests/fixtures/scenarios/env/atmos.yaml (4)

1-2: Base Path Declaration is Correct.

Setting base_path to "./" aligns with expectations for a local deployment reference.


3-9: Terraform Component Configuration is Clear.

The components block sets the Terraform base path and includes logical flags for initialization and auto-approval. Everything appears clean and purposeful.


11-18: Stacks Configuration Verified.

The stacks block defines the base_path, along with the included and excluded paths, which is crucial for managing environment-specific deployments.


19-21: Log Configuration is Acute.

Directing logs to standard error with a level of Info is clear and should support efficient debugging.

tests/test-cases/env.yaml (1)

1-23: Test Case for Environment Export is Solid.

This test case is comprehensive—it correctly sets the working directory, provides the relevant command and arguments, and validates that atmos_base_path and atmos_cli_config_path are exported as intended. The use of regular expressions in the expected stdout adds needed flexibility.

tests/fixtures/components/terraform/env-example/outputs.tf (4)

1-4: Output Definition for atmos_cli_config_path.

The output for atmos_cli_config_path correctly sources its value from the environment variables data block, with a clear and informative description.


6-9: Output Definition for atmos_base_path.

This output correctly mirrors the previous definition to capture the base path. Everything appears well organized.


11-14: Output for 'example' is in Place.

The output for the "EXAMPLE" variable is clearly defined and described, ensuring transparency in the configuration.


16-20: Aggregate Output for all Atmos Variables.

Aggregating all matched environment variables is useful for debugging and further processing. The configuration here is neat.

coderabbitai[bot]
coderabbitai bot previously approved these changes Feb 17, 2025
@mergify mergify bot removed the triage Needs triage label Feb 17, 2025
coderabbitai[bot]
coderabbitai bot previously approved these changes Feb 17, 2025
@mergify mergify bot removed the triage Needs triage label Feb 17, 2025
coderabbitai[bot]
coderabbitai bot previously approved these changes Feb 17, 2025
@mergify mergify bot removed the triage Needs triage label Feb 17, 2025
@haitham911 haitham911 requested a review from osterman February 17, 2025 19:06
Copy link
Member

@aknysh aknysh left a comment

Choose a reason for hiding this comment

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

@haitham911 LGTM, a few comments

Also, in the PR description, add ## what and ## why

@aknysh aknysh added the no-release Do not create a new release (wait for additional code changes) label Feb 17, 2025
@haitham911 haitham911 requested a review from aknysh February 17, 2025 23:21
@aknysh aknysh merged commit a948928 into main Feb 17, 2025
44 checks passed
@aknysh aknysh deleted the exporting-env branch February 17, 2025 23:45
Copy link

These changes were released in v1.163.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no-release Do not create a new release (wait for additional code changes)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants