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

Update YAML function !terraform.output #1048

Merged
merged 8 commits into from
Feb 11, 2025
Merged

Update YAML function !terraform.output #1048

merged 8 commits into from
Feb 11, 2025

Conversation

aknysh
Copy link
Member

@aknysh aknysh commented Feb 11, 2025

what

  • Update YAML function !terraform.output

why

  • When executing !terraform.output for a component that sets environment variables in the env section, set the environment variables from the env section in the child process, and also copy the parent process environment variables into the child process
  • The parent process environment variables can affect the !terraform.output execution, e.g. finding a terraform binary in the PATH

Summary by CodeRabbit

  • Chores

    • Upgraded the Atmos CLI version and a key dependency to newer releases.
  • New Features

    • Added utility functions for enhanced environment variable processing and string splitting.
    • Introduced an alternative Terraform clean operation.
    • Expanded deployment configurations with two new components leveraging environment variables and Terraform outputs.
  • Tests

    • Enhanced test coverage with new cases to validate environment variable and Terraform output integrations.
  • Style

    • Improved configuration formatting for better consistency.

@aknysh aknysh added the patch A minor, backward compatible change label Feb 11, 2025
@aknysh aknysh self-assigned this Feb 11, 2025
Copy link

mergify bot commented Feb 11, 2025

Important

Cloud Posse Engineering Team Review Required

This pull request modifies files that require Cloud Posse's review. Please be patient, and a core maintainer will review your changes.

To expedite this process, reach out to us on Slack in the #pr-reviews channel.

@mergify mergify bot added the needs-cloudposse Needs Cloud Posse assistance label Feb 11, 2025
@aknysh aknysh marked this pull request as ready for review February 11, 2025 03:31
@aknysh aknysh requested review from a team as code owners February 11, 2025 03:31
@aknysh aknysh requested a review from osterman February 11, 2025 03:31
Copy link
Contributor

coderabbitai bot commented Feb 11, 2025

📝 Walkthrough

Walkthrough

This pull request updates the Atmos version across the Dockerfile and GitHub workflow, updates a dependency in go.mod, and enhances environment variable handling in the Terraform output function. New utility functions are added for environment processing and string splitting. Additionally, test scripts are enhanced, adding a new Terraform clean function, new components, workflow commands, and test cases for env and terraform output functionalities. Minor formatting adjustments are also applied to Terraform configuration files.

Changes

File(s) Change Summary
examples/.../Dockerfile, website/.../atlantis.mdx Bump ATMOS_VERSION from 1.160.0 to 1.160.4 in the Dockerfile and GitHub Actions workflow documentation.
go.mod Update dependency github.com/charmbracelet/bubbletea from v1.3.0 to v1.3.2.
internal/exec/terraform_outputs.go Enhance env variable handling by merging parent process env with component-specific settings and update debug logging.
pkg/utils/env_utils.go, pkg/utils/string_utils.go Add new utility functions: EnvironToMap for converting environment variables to a map and SplitStringAtFirstOccurrence for string splitting; update function comment.
tests/cli_terraform_test.go Add runCLITerraformClean function and modify runTerraformClean to remove the --force argument.
tests/.../mock/main.tf Adjust formatting of variable declarations for consistent spacing.
tests/.../deploy/nonprod.yaml, tests/.../terraform-output.yaml, tests/.../atmos-functions.yaml Introduce new components (component-5 and component-6), update deployment workflow commands, and add test cases to validate !env and !terraform.output functionalities.

Sequence Diagram(s)

sequenceDiagram
    participant Test as Test Suite
    participant CleanFn as runCLITerraformClean
    participant Terraform as Terraform CLI
    Test->>CleanFn: Invoke runCLITerraformClean
    CleanFn->>Terraform: Execute "terraform clean"
    Terraform-->>CleanFn: Return output & error
    CleanFn-->>Test: Return result
Loading
sequenceDiagram
    participant Parent as Parent Process
    participant TF as execTerraformOutput
    participant Env as Component Env Settings
    Parent->>TF: Provide environment variables
    TF->>Env: Merge with component-specific env
    Env-->>TF: Return merged environment
    TF->>Log: Log debug message with env info
Loading

Possibly related PRs

Suggested labels

minor

Suggested reviewers

  • osterman
  • milldr
✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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)
pkg/utils/string_utils.go (1)

36-43: Consider using slice instead of fixed-size array.

While the implementation is correct, using [2]string as the return type might be limiting. Consider returning []string for better flexibility in future use cases.

-func SplitStringAtFirstOccurrence(s string, sep string) [2]string {
+func SplitStringAtFirstOccurrence(s string, sep string) []string {
   parts := strings.SplitN(s, sep, 2)
   if len(parts) == 1 {
-    return [2]string{parts[0], ""}
+    return []string{parts[0], ""}
   }
-  return [2]string{parts[0], parts[1]}
+  return parts
}
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between a8757da and b932be6.

⛔ Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
📒 Files selected for processing (11)
  • examples/quick-start-advanced/Dockerfile (1 hunks)
  • go.mod (1 hunks)
  • internal/exec/terraform_outputs.go (1 hunks)
  • pkg/utils/env_utils.go (2 hunks)
  • pkg/utils/string_utils.go (1 hunks)
  • tests/cli_terraform_test.go (1 hunks)
  • tests/fixtures/components/terraform/mock/main.tf (1 hunks)
  • tests/fixtures/scenarios/atmos-functions/stacks/deploy/nonprod.yaml (1 hunks)
  • tests/fixtures/scenarios/atmos-functions/stacks/workflows/terraform-output.yaml (1 hunks)
  • tests/test-cases/atmos-functions.yaml (1 hunks)
  • website/docs/integrations/atlantis.mdx (1 hunks)
✅ Files skipped from review due to trivial changes (2)
  • tests/fixtures/components/terraform/mock/main.tf
  • go.mod
🧰 Additional context used
🧠 Learnings (1)
examples/quick-start-advanced/Dockerfile (2)
Learnt from: aknysh
PR: cloudposse/atmos#775
File: examples/quick-start-advanced/Dockerfile:9-9
Timestamp: 2024-11-12T05:52:05.088Z
Learning: It is acceptable to set `ARG ATMOS_VERSION` to a future version like `1.105.0` in `examples/quick-start-advanced/Dockerfile` if that will be the next release.
Learnt from: osterman
PR: cloudposse/atmos#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.
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Summary
🔇 Additional comments (10)
pkg/utils/env_utils.go (2)

8-8: LGTM! Grammar improvement in comment.

The verb tense correction from "convert" to "converts" improves the documentation clarity.


20-30: LGTM! Well-structured environment variable conversion.

The new EnvironToMap function effectively converts environment variables into a map, which is essential for preserving parent process environment variables. The implementation is clean and uses the new SplitStringAtFirstOccurrence helper function.

tests/cli_terraform_test.go (1)

151-161: LGTM! Well-structured test function.

The new runCLITerraformClean function follows consistent patterns with existing test functions and provides good coverage for non-forced clean operations.

🧰 Tools
🪛 golangci-lint (1.62.2)

151-151: func runCLITerraformClean is unused

(unused)

internal/exec/terraform_outputs.go (1)

133-141: LGTM! Robust environment variable handling.

The implementation correctly:

  1. Preserves parent process environment variables
  2. Allows component-specific overrides
  3. Provides clear debug logging

This enhancement ensures proper environment variable inheritance, which is crucial for Terraform binary discovery and execution.

tests/fixtures/scenarios/atmos-functions/stacks/workflows/terraform-output.yaml (1)

9-10: LGTM! Well-structured test workflow additions.

The new workflow steps for component-5 and component-6 create a good test chain for validating environment variable handling and terraform output functionality.

tests/fixtures/scenarios/atmos-functions/stacks/deploy/nonprod.yaml (1)

31-40: LGTM! Well-designed test components.

The component chain effectively tests the environment variable handling:

  • component-5 validates environment variable injection
  • component-6 validates that terraform.output can access values from components using environment variables
examples/quick-start-advanced/Dockerfile (1)

9-9: LGTM! Version update follows team conventions.

The ATMOS_VERSION update to 1.160.4 is consistent with other files and aligns with team preferences for version handling.

tests/test-cases/atmos-functions.yaml (2)

49-66: LGTM! Well-structured environment variable test.

The test case effectively validates environment variable injection with proper assertions and expected outputs.


68-83: LGTM! Comprehensive terraform.output test.

The test case thoroughly validates that terraform.output can access values from components using environment variables.

website/docs/integrations/atlantis.mdx (1)

676-676: LGTM! Documentation version update.

The ATMOS_VERSION update to 1.160.4 in the GitHub Actions example maintains consistency with other files.

@aknysh aknysh merged commit a155dd3 into main Feb 11, 2025
46 of 47 checks passed
@aknysh aknysh deleted the update-yaml-funcs-4 branch February 11, 2025 04:02
@mergify mergify bot removed the needs-cloudposse Needs Cloud Posse assistance label Feb 11, 2025
Copy link

These changes were released in v1.160.4.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
patch A minor, backward compatible change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants