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

docs: add example for complex usage of !include with triple quotes #1086

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

Conversation

Benbentwo
Copy link
Member

@Benbentwo Benbentwo commented Feb 21, 2025

what

  • Added documentation for the !include YAML function in Atmos.

why

  • To help users understand and utilize the !include function in their Atmos stack manifests.

references

Summary by CodeRabbit

  • Documentation

    • Enhanced documentation with a new example demonstrating advanced usage of the include functionality. The example showcases how to integrate remote JSON files and query specific keys using intricate quoting techniques.
  • New Features

    • Introduced a templates section in the YAML configuration, enabling new template settings.
    • Added new variables in various configuration files to support additional data structures and configurations for enhanced functionality.

@Benbentwo Benbentwo requested a review from a team as a code owner February 21, 2025 17:24
@mergify mergify bot added the triage Needs triage label Feb 21, 2025
Copy link
Contributor

coderabbitai bot commented Feb 21, 2025

📝 Walkthrough

Walkthrough

The changes introduce enhancements to the documentation and configuration files related to the !include function and YAML settings. An example is added to the documentation to illustrate using triple double quotes for complex YQ expressions. Additionally, new variables and sections are added to various YAML and JSON configuration files, expanding their functionality without altering existing features.

Changes

File Path Change Summary
website/docs/core-concepts/stacks/yaml-functions/include.mdx Added an example demonstrating the usage of triple double quotes in the !include function for complex YQ expressions on a remote JSON file.
tests/fixtures/scenarios/atmos-include-yaml-function/atmos.yaml Introduced a new templates section with settings containing keys enabled, sprig, and gomplate, all set to true.
tests/fixtures/scenarios/atmos-include-yaml-function/config/vars.json Added new variables: "other_list_var" with values ["d", "e", "f"] and "list_objects" containing an object with "hyphenated-list-var" mapping to ["x", "y", "z"].
tests/fixtures/scenarios/atmos-include-yaml-function/config/vars.tfvars Added new variables other_list_var and list_objects, and reformatted list_var for consistency.
tests/fixtures/scenarios/atmos-include-yaml-function/config/vars.yaml Introduced new variables other_list_var and list_objects with similar structures as in the JSON file.
tests/fixtures/scenarios/atmos-include-yaml-function/stacks/deploy/nonprod.yaml Added variables complex_yq_var, hyphenated_list_var, and http_var, utilizing the !include directive for external JSON files and complex filters.

Possibly related PRs

  • Update !terraform.output and atmos.Component functions #944: The changes in the main PR, which enhance the documentation for the !include function with complex YQ expressions, are related to the retrieved PR that updates the !terraform.output function to support YQ expressions for handling complex output types. Both PRs involve improvements to the use of YQ expressions in their respective functions.

Suggested labels

no-release

Suggested reviewers

  • aknysh
  • mcalhoun
  • osterman

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)
website/docs/core-concepts/stacks/yaml-functions/include.mdx (1)

173-179: Clarify Triple Quotes Example

The new example clearly demonstrates how to handle cases that require triple double quotes when combining file paths and complex YQ expressions. For extra clarity, consider adding a brief inline comment or expanding the surrounding text to explain when and why the triple quotes are necessary (for instance, when the YQ expression itself contains syntax that could be misinterpreted by YAML). This extra detail could help users quickly understand the rationale behind this syntax choice.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 141c731 and 690c877.

📒 Files selected for processing (1)
  • website/docs/core-concepts/stacks/yaml-functions/include.mdx (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: Build (windows-latest, windows)
  • GitHub Check: website-deploy-preview
  • GitHub Check: Analyze (go)
  • GitHub Check: Summary

coderabbitai[bot]
coderabbitai bot previously approved these changes Feb 21, 2025
@@ -170,3 +170,9 @@ On macOS and Linux:
values: !include './values.yaml "<yq-expression-with-spaces>"'
description: !include '"component description.md"'
```

Sometimes for more complex cases you may need to utilize 3x double quotes, for examples:
Copy link
Member

Choose a reason for hiding this comment

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

I rather we address the root cause. This is absurd. This is a hack, a workaround. This is not the solution.

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: 1

🧹 Nitpick comments (2)
tests/fixtures/scenarios/atmos-include-yaml-function/config/vars.yaml (1)

11-19: Fix YAML formatting issues.

The YAML linter reports trailing spaces and incorrect indentation.

Apply this diff to fix the formatting:

-other_list_var: 
+other_list_var:
   - d
   - e
   - f
 list_objects:
   - hyphenated-list-var:
-    - x
-    - y
-    - z
+      - x
+      - y
+      - z
🧰 Tools
🪛 YAMLlint (1.35.1)

[error] 11-11: trailing spaces

(trailing-spaces)


[warning] 17-17: wrong indentation: expected 6 but found 4

(indentation)

tests/fixtures/scenarios/atmos-include-yaml-function/atmos.yaml (1)

24-30: Document template settings and consider security implications.

While enabling template features enhances functionality, it's important to document:

  1. The purpose and impact of each template setting
  2. Security considerations when enabling template engines
  3. Best practices for using these features safely

Consider adding documentation about these settings and their security implications. Would you like me to help draft this documentation?

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 690c877 and b378054.

📒 Files selected for processing (5)
  • tests/fixtures/scenarios/atmos-include-yaml-function/atmos.yaml (1 hunks)
  • tests/fixtures/scenarios/atmos-include-yaml-function/config/vars.json (1 hunks)
  • tests/fixtures/scenarios/atmos-include-yaml-function/config/vars.tfvars (1 hunks)
  • tests/fixtures/scenarios/atmos-include-yaml-function/config/vars.yaml (1 hunks)
  • tests/fixtures/scenarios/atmos-include-yaml-function/stacks/deploy/nonprod.yaml (1 hunks)
🧰 Additional context used
🪛 YAMLlint (1.35.1)
tests/fixtures/scenarios/atmos-include-yaml-function/config/vars.yaml

[error] 11-11: trailing spaces

(trailing-spaces)


[warning] 17-17: wrong indentation: expected 6 but found 4

(indentation)

⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Build (windows-latest, windows)
  • GitHub Check: Summary
🔇 Additional comments (6)
tests/fixtures/scenarios/atmos-include-yaml-function/config/vars.json (1)

9-22: LGTM! JSON structure is well-formed and consistent.

The new variables are properly formatted and maintain consistency with other configuration files.

tests/fixtures/scenarios/atmos-include-yaml-function/stacks/deploy/nonprod.yaml (5)

17-17: Clarify the relative path comment.

The comment on this line clearly reminds users that relative paths are based on the location of the file with the !include directive, which is helpful for avoiding confusion when referencing files.


18-18: Validate the complex YQ expression.

The inclusion syntax for complex_yq_var—combining .list_var and .other_list_var from "../../config/vars.json"—is a neat way to demonstrate advanced usage. Please verify that concatenating these variables produces the intended result and that the referenced keys are available in all relevant configurations.


19-19: Review handling of hyphenated keys.

The hyphenated_list_var includes a hyphenated key (hyphenated-list-var), and the expression concatenating .list_var, .other_list_var, and .list_objects[0].hyphenated-list-var is interesting. Confirm that the parser correctly processes hyphenated keys within this context.


20-20: Affirm the triple quotes note.

The inline comment explaining that the HTTP include requires triple quotes due to the space in the jq filter is clear and beneficial for users who might run into similar issues.


21-21: Confirm triple quotes usage in HTTP include.

The http_var correctly demonstrates how to use triple double quotes to wrap a complex filter with spaces. Please ensure that this syntax is compliant with your YAML parser and that it functions as expected in practice.

Comment on lines +9 to +13
other_list_var : [
"d",
"e",
"f"
]
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Standardize variable assignment syntax and avoid hyphens in Terraform variable names.

The new variables use : for assignment while existing variables use =. Additionally, the hyphenated key name might cause issues in Terraform.

Apply this diff to maintain consistency and Terraform compatibility:

-other_list_var : [
+other_list_var = [
   "d",
   "e",
   "f"
 ]
-list_objects : [
+list_objects = [
   {
-    hyphenated-list-var : [
+    hyphenated_list_var = [
      "x",
      "y",
      "z"
    ]
   }
 ]

Also applies to: 14-22

complex_yq_var: !include '"../../config/vars.json" ".list_var + .other_list_var"'
hyphenated_list_var: !include '"../../config/vars.json" ".list_var + .other_list_var + .list_objects[0].hyphenated-list-var"'
### http include with space based jq filter requires triple quotes.
http_var: !include '"https://atmos.tools/schemas/atmos/atmos-manifest/1.0/atmos-manifest.json" """.definitions.backend_type.enum + .definitions.metadata.properties.type.enum"""'
Copy link
Member

Choose a reason for hiding this comment

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

Can we test what we discussed on Friday ARB?

@@ -19,3 +19,12 @@ stacks:
logs:
file: "/dev/stderr"
level: Info

Copy link
Member

Choose a reason for hiding this comment

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

Suggested change

Comment on lines +176 to +177
vars:
my_array: !include '"https://foo.com/bar.json" """.some_key.array_one + .some_key.hyphenated-field.array_two"""'
Copy link
Member

Choose a reason for hiding this comment

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

Please try this instead

Suggested change
vars:
my_array: !include '"https://foo.com/bar.json" """.some_key.array_one + .some_key.hyphenated-field.array_two"""'
vars:
my_array: !include >
https://foo.com/bar.json
".some_key.array_one + .some_key.hyphenated-field.array_two"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size/s triage Needs triage
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants