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

feat: TF_CLI_ARGS_* Handling for -var-file #898

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

milldr
Copy link
Member

@milldr milldr commented Dec 27, 2024

what

  • Added logic and warning messages when the user specifies any TF_CLI_ARGS_* environment variable for -var-file, since this may conflict with Atmos generated var files.
  • Added to 3 places: terraform shell, terraform as a ENV var, terraform as a component env var

why

  • When executing Terraform Shell, we should append generate var file to the (if) specified var file rather than overwriting it
  • When executing Terraform, var files are already appended (merged). We should add a warning nonetheless

references

2024-12-27 10 13 41

Summary by CodeRabbit

  • New Features

    • Enhanced error handling and logging for Terraform command-line arguments.
    • Added warnings for potential conflicts with existing environment variable settings related to -var-file arguments.
  • Bug Fixes

    • Improved management of Terraform command-line arguments to prevent unintentional overwriting of variable files.

@mergify mergify bot added the triage Needs triage label Dec 27, 2024
@milldr milldr added minor New features that do not break anything and removed triage Needs triage labels Dec 27, 2024
@milldr milldr marked this pull request as ready for review December 27, 2024 15:15
@milldr milldr requested a review from a team as a code owner December 27, 2024 15:15
Copy link
Contributor

coderabbitai bot commented Dec 27, 2024

📝 Walkthrough

Walkthrough

The pull request focuses on improving the handling of Terraform command-line arguments and environment variables in the Atmos shell utility functions. The changes introduce a more robust approach to managing -var-file arguments, adding warning mechanisms to prevent unintentional overwriting of existing environment variables. The modifications enhance logging and error handling by checking for pre-existing Terraform-related environment variables and providing user notifications about potential conflicts.

Changes

File Change Summary
internal/exec/shell_utils.go Modified execTerraformShellCommand to implement more structured handling of Terraform command-line arguments
internal/exec/terraform.go Added checks and warnings for existing -var-file arguments in Terraform-related environment variables

Assessment against linked issues

Objective Addressed Explanation
Warn about TF_CLI_ env variable replacement [DEV-2793]
Append to existing environment variables instead of replacing

Possibly related PRs

Suggested reviewers

  • osterman
  • aknysh
  • Gowiem

Tip

CodeRabbit's docstrings feature is now available as part of our Early Access Program! Simply use the command @coderabbitai generate docstrings to have CodeRabbit automatically generate docstrings for your pull request. We would love to hear your feedback on Discord.


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)
internal/exec/terraform.go (1)

262-264: Catching var-file collisions in component environment ensures thorough coverage.
These lines do a great job of warning users when environment-level settings might be overridden.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 1aa75c6 and 42c3026.

📒 Files selected for processing (2)
  • internal/exec/shell_utils.go (1 hunks)
  • internal/exec/terraform.go (1 hunks)
🔇 Additional comments (4)
internal/exec/shell_utils.go (3)

188-190: Neat definition of terraform commands.
This approach centralizes the commands that may require var-file handling, simplifying future maintenance and extension.


191-197: Clear warning message for potential collisions.
It is helpful to log a warning whenever these TF_CLI_ARGS variables contain a “-var-file” argument, reducing user confusion.


198-200: Appending the var file reference to each command is straightforward.
Ensure users understand that this logic overrides any existing “-var-file” specification at runtime.

internal/exec/terraform.go (1)

248-257: Collisions detection is consistent with shell_utils.
Capturing conflicts across both the shell and terraform commands maintains consistent user visibility.

u.LogWarning(atmosConfig, "Found var-file in environment! This may be overwritten by Atmos")
}
// Set the Terraform environment variable to reference the var file
componentEnvList = append(componentEnvList, fmt.Sprintf("%s=-var-file=%s", envVar, varFile))
Copy link
Member

@osterman osterman Dec 27, 2024

Choose a reason for hiding this comment

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

We still haven't solved the underlying intent here which is that we should also allow the user to specify their own TF_CLI_ARGS, which would be appending to the current value of the corresponding ENV. Now we squash whatever value was there. If the value is set to anything, not just a var file, we should warn that this could interfere with atmos behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
minor New features that do not break anything
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants