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 !terraform.output and atmos.Component functions #944

Merged
merged 9 commits into from
Jan 17, 2025

Conversation

aknysh
Copy link
Member

@aknysh aknysh commented Jan 17, 2025

what

  • Improve !terraform.output YAML function
  • Improve atmos.Component template function

why

  • When executing !terraform.output and atmos.Component functions, honor the components.terraform.init_run_reconfigure setting in atmos.yaml. If it's set to true, add the -reconfigure flag to the terraform output command when executing it to get the component outputs. This prevents an issue when you use the functions to retrieve the outputs of the same component from many different stacks (without using the -reconfigure flag, Terraform detects that the backend configuration has changed and complains about it)

  • Use YQ expressions to retrieve items from complex output types

    To retrieve items from complex output types such as maps and lists, or do any kind of filtering or querying,
    you can utilize YQ expressions.

    For example:

    • Retrieve the first item from a list
    subnet_id1: !terraform.output vpc .private_subnet_ids[0]
    • Read a key from a map
    username: !terraform.output config .config_map.username

    Examples

    components:
      terraform:
        my_lambda_component:
          vars:
            vpc_config:
              # Output of type list
              subnet_ids: !terraform.output vpc private_subnet_ids
              # Use a YQ expression to get an item from the list
              subnet_id1: !terraform.output vpc .private_subnet_ids[0]
              # Output of type map
              config_map: !terraform.output config {{ .stack }} config_map
              # Use a YQ expression to get a value from the map
              username: !terraform.output config .config_map.username

references

Summary by CodeRabbit

Summary by CodeRabbit

  • Dependency Updates

    • Upgraded multiple dependencies, including AWS SDK, Go Container Registry, and other libraries.
    • Bumped Atmos tool version from 1.144.0 to 1.149.0.
  • Documentation

    • Updated documentation for the !terraform.output function, including usage examples and caching behavior.
    • Improved Atlantis integration documentation reflecting the updated Atmos version.
  • Improvements

    • Enhanced Terraform output retrieval logic and error handling.

@aknysh aknysh added the minor New features that do not break anything label Jan 17, 2025
@aknysh aknysh self-assigned this Jan 17, 2025
@aknysh aknysh requested a review from a team as a code owner January 17, 2025 00:00
Copy link

mergify bot commented Jan 17, 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.

Copy link
Contributor

coderabbitai bot commented Jan 17, 2025

📝 Walkthrough

Walkthrough

This pull request encompasses multiple updates across the Atmos project, focusing on version upgrades, dependency management, and documentation improvements. The changes include updating the Atmos tool version, modifying Go dependencies, refactoring Terraform output handling, enhancing documentation for the !terraform.output function, and making minor adjustments to integration guides.

Changes

File Change Summary
examples/quick-start-advanced/Dockerfile Upgraded Atmos version from 1.144.0 to 1.149.0
go.mod Updated Go version to 1.23.5 and upgraded multiple dependencies
internal/exec/terraform_outputs.go Refactored Terraform output retrieval and initialization logic
internal/exec/yaml_func_terraform_output.go Removed terraformOutputFuncSyncMap synchronization variable
tests/fixtures/scenarios/complete/stacks/catalog/terraform/template-functions-test2/defaults.yaml Added and modified template function output variables
website/docs/core-concepts/stacks/yaml-functions/terraform.output.mdx Updated documentation for !terraform.output function
website/docs/integrations/atlantis.mdx Updated Atmos version in GitHub Actions workflow

Possibly related PRs

Suggested reviewers

  • osterman
  • Gowiem

📜 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 d422dc3 and 4f44ab1.

📒 Files selected for processing (1)
  • go.mod (11 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • go.mod
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • 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: 2

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 2254b73 and d422dc3.

⛔ Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
📒 Files selected for processing (7)
  • examples/quick-start-advanced/Dockerfile (1 hunks)
  • go.mod (11 hunks)
  • internal/exec/terraform_outputs.go (7 hunks)
  • internal/exec/yaml_func_terraform_output.go (0 hunks)
  • tests/fixtures/scenarios/complete/stacks/catalog/terraform/template-functions-test2/defaults.yaml (2 hunks)
  • website/docs/core-concepts/stacks/yaml-functions/terraform.output.mdx (4 hunks)
  • website/docs/integrations/atlantis.mdx (1 hunks)
💤 Files with no reviewable changes (1)
  • internal/exec/yaml_func_terraform_output.go
✅ Files skipped from review due to trivial changes (1)
  • website/docs/integrations/atlantis.mdx
🧰 Additional context used
📓 Learnings (4)
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.
website/docs/core-concepts/stacks/yaml-functions/terraform.output.mdx (3)
Learnt from: aknysh
PR: cloudposse/atmos#810
File: examples/tests/stacks/catalog/terraform/template-functions-test2/defaults.yaml:28-32
Timestamp: 2024-12-01T00:33:20.298Z
Learning: In `examples/tests/stacks/catalog/terraform/template-functions-test2/defaults.yaml`, `!exec atmos terraform output` is used in examples to demonstrate its usage, even though `!terraform.output` is the recommended approach according to the documentation.
Learnt from: aknysh
PR: cloudposse/atmos#810
File: website/docs/core-concepts/stacks/yaml-functions/terraform.output.mdx:0-0
Timestamp: 2024-12-03T04:01:16.446Z
Learning: In the `terraform.output.mdx` documentation file (`website/docs/core-concepts/stacks/yaml-functions/terraform.output.mdx`), the cache invalidation and cache scope behavior for the `!terraform.output` function are already described.
Learnt from: aknysh
PR: cloudposse/atmos#810
File: website/docs/core-concepts/stacks/yaml-functions/terraform.output.mdx:104-110
Timestamp: 2024-12-03T03:49:30.395Z
Learning: In the documentation for `!terraform.output`, warnings about template variable availability are already covered in other sections, so no need to suggest adding them here.
internal/exec/terraform_outputs.go (1)
Learnt from: aknysh
PR: cloudposse/atmos#810
File: internal/exec/terraform_utils.go:40-213
Timestamp: 2024-12-03T05:18:49.169Z
Learning: In the context of the Atmos project, it's acceptable for functions like `execTerraformOutput` to remain as single functions if they perform a single purpose, such as retrieving Terraform outputs for a component in a stack, even if the function is lengthy.
tests/fixtures/scenarios/complete/stacks/catalog/terraform/template-functions-test2/defaults.yaml (1)
Learnt from: aknysh
PR: cloudposse/atmos#810
File: examples/tests/stacks/catalog/terraform/template-functions-test2/defaults.yaml:28-32
Timestamp: 2024-12-01T00:33:20.298Z
Learning: In `examples/tests/stacks/catalog/terraform/template-functions-test2/defaults.yaml`, `!exec atmos terraform output` is used in examples to demonstrate its usage, even though `!terraform.output` is the recommended approach according to the documentation.
🪛 GitHub Actions: Dependency Review
go.mod

[error] Incompatible license detected: github.com/magiconair/[email protected] uses BSD-2-Clause license which is not allowed

⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Acceptance Tests (windows-latest, windows)
  • GitHub Check: Summary
🔇 Additional comments (11)
internal/exec/terraform_outputs.go (3)

140-146: LGTM! Good addition of the -reconfigure flag support.

The implementation correctly respects the components.terraform.init_run_reconfigure setting from atmos.yaml. This change helps prevent backend configuration errors when retrieving outputs from the same component across multiple stacks.


258-281: Well-structured refactoring of output variable handling!

The refactoring improves the code by:

  1. Using YQ expressions for complex output types
  2. Adding proper prefix handling for output paths
  3. Providing clearer error messages

291-307: Consistent implementation for static remote state outputs.

The changes maintain consistency with the regular output handling, ensuring both paths handle YQ expressions similarly.

examples/quick-start-advanced/Dockerfile (1)

9-9: LGTM! Version update is aligned with team practices.

The update to ATMOS_VERSION=1.149.0 follows the established pattern of pinning to the next future version.

tests/fixtures/scenarios/complete/stacks/catalog/terraform/template-functions-test2/defaults.yaml (1)

47-53: Excellent test coverage for YQ expressions!

The new test cases comprehensively cover various YQ expression patterns:

  • Array indexing with and without dot prefix
  • Object property access
  • Nested property access
website/docs/core-concepts/stacks/yaml-functions/terraform.output.mdx (2)

48-71: Clear and comprehensive documentation for YQ expressions!

The new section effectively:

  • Introduces YQ expressions for complex outputs
  • Provides practical examples
  • Links to additional YQ documentation

87-92: Well-chosen practical examples!

The examples effectively demonstrate both list and map access patterns using YQ expressions.

go.mod (4)

55-55: OAuth2 package update requires review.

The OAuth2 package update to v0.25.0 might affect authentication flows. Ensure all OAuth2-related functionality is tested after this update.

✅ Verification successful

OAuth2 package update is safe

The update to oauth2 v0.25.0 is safe as the codebase only uses stable core functionality (StaticTokenSource, Token, NewClient) for GitHub authentication. No complex OAuth2 flows are implemented that could be affected by this update.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for OAuth2 usage patterns
rg "oauth2\." -A 3

Length of output: 346

🧰 Tools
🪛 GitHub Actions: Dependency Review

[error] Incompatible license detected: github.com/magiconair/[email protected] uses BSD-2-Clause license which is not allowed


90-104: AWS SDK indirect dependencies need alignment.

Multiple AWS SDK indirect dependencies have been updated. Ensure they align with the main AWS SDK version to prevent compatibility issues.

✅ Verification successful

AWS SDK dependencies are properly aligned

The indirect dependencies are correctly managed by Go modules, and the version differences are expected as AWS services evolve independently. The internal package versions are consistent where required, ensuring compatibility.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check version alignment of AWS SDK indirect dependencies
rg "github.com/aws/aws-sdk-go-v2/.*v\d+\.\d+\.\d+" --no-filename | sort | uniq

Length of output: 8188

🧰 Tools
🪛 GitHub Actions: Dependency Review

[error] Incompatible license detected: github.com/magiconair/[email protected] uses BSD-2-Clause license which is not allowed


10-11: Consider pinning AWS SDK dependencies to compatible versions.

The AWS SDK dependencies have been updated to newer versions. Ensure all AWS SDK packages are updated together to maintain version compatibility.

✅ Verification successful

AWS SDK dependencies are properly aligned

All AWS SDK dependencies are at compatible versions. The version differences between packages are normal and expected, as different components can have different release cycles while maintaining compatibility.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for version mismatches in AWS SDK dependencies
rg "github.com/aws/aws-sdk-go-v2.*v\d+\.\d+\.\d+" -A 1

Length of output: 9374

🧰 Tools
🪛 GitHub Actions: Dependency Review

[error] Incompatible license detected: github.com/magiconair/[email protected] uses BSD-2-Clause license which is not allowed


40-40: Verify YQ version compatibility.

The YQ package has been updated to v4.45.1. This is a significant version bump that might introduce breaking changes in YAML processing.

✅ Verification successful

YQ v4.45.1 update appears safe 🛡️

The codebase uses stable YQ v4 APIs for basic YAML processing (evaluation, encoding, decoding) in a single utility function. These core features are unlikely to have breaking changes within the v4.x series.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for YQ usage patterns that might be affected by the version update
ast-grep --pattern 'yq.$$$'

Length of output: 29


Script:

#!/bin/bash
# Search for YQ imports and usage
rg -l "github.com/mikefarah/yq" --type go
rg -l "exec.Command.*yq" --type go
rg -l "yaml\." --type go -A 3

Length of output: 309


Script:

#!/bin/bash
# Examine YQ usage patterns
cat pkg/utils/yq_utils.go
rg -p "yq\." --type go

Length of output: 1972

🧰 Tools
🪛 GitHub Actions: Dependency Review

[error] Incompatible license detected: github.com/magiconair/[email protected] uses BSD-2-Clause license which is not allowed

go.mod Outdated Show resolved Hide resolved
go.mod Show resolved Hide resolved
coderabbitai[bot]
coderabbitai bot previously approved these changes Jan 17, 2025
@aknysh
Copy link
Member Author

aknysh commented Jan 17, 2025

@coderabbitai please review

Copy link
Contributor

coderabbitai bot commented Jan 17, 2025

@aknysh i'll review the changes in the pr.

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@aknysh aknysh merged commit 83bd190 into main Jan 17, 2025
44 checks passed
@aknysh aknysh deleted the update-terraform-output-yaml-func branch January 17, 2025 00:46
@mergify mergify bot removed the needs-cloudposse Needs Cloud Posse assistance label Jan 17, 2025
Copy link

These changes were released in v1.149.0.

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