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(DEV-2936): Spinner for !terraform.output #947

Merged
merged 14 commits into from
Jan 24, 2025

Conversation

milldr
Copy link
Member

@milldr milldr commented Jan 17, 2025

what

  • Created a charmbracelet spinner when loading terraform output with !terraform.output
  • Centralized spinner model in terraform_outputs_model.go
  • Added success/failure indicators for terraform output operations
  • Improved user feedback during terraform output operations

why

  • Provides visual feedback during potentially long-running terraform output operations
  • Maintains consistency with other Atmos operations (like vendoring) that use spinners
  • Improves user experience by clearly indicating:
    • When an operation is in progress
    • When an operation succeeds (✓)
    • When an operation fails (✗)
  • Makes it clear which component and stack is being queried for outputs

references

2025-01-17 12 36 03

Summary by CodeRabbit

Release Notes

  • New Features

    • Added spinner UI for improved visual feedback during Terraform operations
    • Enhanced Terraform output retrieval with better error handling
  • Testing

    • Added new test cases for Terraform output function
    • Introduced mock Terraform components for testing output scenarios
  • Configuration

    • Updated .gitignore to exclude cache and vendor directories
    • Added new Atmos configuration files for deployment scenarios
  • Performance

    • Increased acceptance test timeout from 2 to 10 minutes

@mergify mergify bot added the triage Needs triage label Jan 17, 2025
@milldr milldr added minor New features that do not break anything and removed triage Needs triage labels Jan 17, 2025
coderabbitai[bot]
coderabbitai bot previously approved these changes Jan 18, 2025
@osterman
Copy link
Member

Looks like it's failing on:

=== RUN   TestCLICommands/terraform_output_function
    cli_test.go:486: Reason: Expected exit code 0, got 2
    cli_test.go:392: Description: Ensure the !terraform.output function works.
    cli_test.go:508: Reason: stdout did not match pattern "Fetching baz output from component-3 in nonprod".
    cli_test.go:509: Output: ""
    cli_test.go:508: Reason: stdout did not match pattern "Fetching foo output from component-1 in nonprod".
    cli_test.go:509: Output: ""
    cli_test.go:508: Reason: stdout did not match pattern "Fetching bar output from component-2 in nonprod".
    cli_test.go:509: Output: ""
    cli_test.go:397: Stdout mismatch for test: terraform output function
    cli_test.go:508: Reason: stderr did not match pattern "^$".
    cli_test.go:509: Output: "panic: interface conversion: io.Writer is *os.File, not *term.TerminalWriter\n\ngoroutine 1 [running]:\ngithub.com/cloudposse/atmos/cmd.renderError({{0x103382b41, 0x17}, {0x0, 0x0}, {0x0, 0x0}})\n\t/Users/runner/work/atmos/atmos/cmd/workflow.go:37 +0x2b4\ngithub.com/cloudposse/atmos/cmd.init.func38(0x107465260, {0x14000e96240, 0x1, 0x3})\n\t/Users/runner/work/atmos/atmos/cmd/workflow.go:159 +0x45c\ngithub.com/spf13/cobra.(*Command).execute(0x107465260, {0x14000e961e0, 0x3, 0x3})\n\t/Users/runner/go/pkg/mod/github.com/spf13/[email protected]/command.go:989 +0x81c\ngithub.com/spf13/cobra.(*Command).ExecuteC(0x107462460)\n\t/Users/runner/go/pkg/mod/github.com/spf13/[email protected]/command.go:1117 +0x344\ngithub.com/spf13/cobra.(*Command).Execute(...)\n\t/Users/runner/go/pkg/mod/github.com/spf13/[email protected]/command.go:1041\ngithub.com/cloudposse/atmos/cmd.Execute()\n\t/Users/runner/work/atmos/atmos/cmd/root.go:123 +0x304\nmain.main()\n\t/Users/runner/work/atmos/atmos/main.go:10 +0x30\n"
    cli_test.go:402: Stderr mismatch for test: terraform output function

@milldr
Copy link
Member Author

milldr commented Jan 22, 2025

Looks like it's failing on:

=== RUN   TestCLICommands/terraform_output_function
    cli_test.go:486: Reason: Expected exit code 0, got 2
    cli_test.go:392: Description: Ensure the !terraform.output function works.
    cli_test.go:508: Reason: stdout did not match pattern "Fetching baz output from component-3 in nonprod".
    cli_test.go:509: Output: ""
    cli_test.go:508: Reason: stdout did not match pattern "Fetching foo output from component-1 in nonprod".
    cli_test.go:509: Output: ""
    cli_test.go:508: Reason: stdout did not match pattern "Fetching bar output from component-2 in nonprod".
    cli_test.go:509: Output: ""
    cli_test.go:397: Stdout mismatch for test: terraform output function
    cli_test.go:508: Reason: stderr did not match pattern "^$".
    cli_test.go:509: Output: "panic: interface conversion: io.Writer is *os.File, not *term.TerminalWriter\n\ngoroutine 1 [running]:\ngithub.com/cloudposse/atmos/cmd.renderError({{0x103382b41, 0x17}, {0x0, 0x0}, {0x0, 0x0}})\n\t/Users/runner/work/atmos/atmos/cmd/workflow.go:37 +0x2b4\ngithub.com/cloudposse/atmos/cmd.init.func38(0x107465260, {0x14000e96240, 0x1, 0x3})\n\t/Users/runner/work/atmos/atmos/cmd/workflow.go:159 +0x45c\ngithub.com/spf13/cobra.(*Command).execute(0x107465260, {0x14000e961e0, 0x3, 0x3})\n\t/Users/runner/go/pkg/mod/github.com/spf13/[email protected]/command.go:989 +0x81c\ngithub.com/spf13/cobra.(*Command).ExecuteC(0x107462460)\n\t/Users/runner/go/pkg/mod/github.com/spf13/[email protected]/command.go:1117 +0x344\ngithub.com/spf13/cobra.(*Command).Execute(...)\n\t/Users/runner/go/pkg/mod/github.com/spf13/[email protected]/command.go:1041\ngithub.com/cloudposse/atmos/cmd.Execute()\n\t/Users/runner/work/atmos/atmos/cmd/root.go:123 +0x304\nmain.main()\n\t/Users/runner/work/atmos/atmos/main.go:10 +0x30\n"
    cli_test.go:402: Stderr mismatch for test: terraform output function

Yes I know what needs to be fixed (handling TTY), but havent had time yet. Will get to it as soon as I can

@milldr milldr force-pushed the DEV-2936/terraform-output-spinner branch from 9a0de76 to 6dfb0c4 Compare January 23, 2025 23:21
Copy link

mergify bot commented Jan 23, 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 Jan 23, 2025
@milldr milldr marked this pull request as ready for review January 24, 2025 00:36
@milldr milldr requested review from a team as code owners January 24, 2025 00:36
Copy link
Contributor

coderabbitai bot commented Jan 24, 2025

📝 Walkthrough

Walkthrough

This pull request introduces enhancements to the Atmos project's infrastructure, focusing on improving the Terraform output retrieval process and configuration management. The changes span multiple files, including .gitignore, Makefile, and various test fixtures. The primary focus is on adding a spinner UI for better user feedback during Terraform output operations, extending test scenarios, and refining configuration management.

Changes

File Change Summary
.gitignore Added entries to ignore cache and vendored component files
Makefile Extended acceptance test timeout from 2 to 10 minutes
internal/exec/spinner_utils.go New file with spinner model implementation
internal/exec/terraform_outputs.go Added spinner UI for Terraform output retrieval
tests/fixtures/... Added new configuration and test files for Terraform output function testing

Sequence Diagram

sequenceDiagram
    participant User
    participant AtmosCLI
    participant TerraformComponent
    participant Spinner

    User->>AtmosCI: Request Terraform output
    AtmosCI->>Spinner: Initialize spinner
    Spinner->>AtmosCI: Spinner running
    AtmosCI->>TerraformComponent: Retrieve outputs
    TerraformComponent-->>AtmosCI: Return outputs
    AtmosCI->>Spinner: Stop spinner
    Spinner->>User: Display results
Loading

Assessment against linked issues

Objective Addressed Explanation
Add status indicator for loading terraform output [DEV-2936]

Possibly related PRs

Suggested reviewers

  • osterman
✨ 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 (4)
tests/fixtures/components/terraform/mock/main.tf (2)

1-4: Variable declarations.
Having defaults is sensible for testing. Consider adding descriptions to clarify usage.


6-9: Combining variables.
These string variables appear uniform. You might combine or programmatically set them if they share logic.

Also applies to: 11-14

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

10-10: Remove Trailing Whitespace

There's trailing whitespace at the end of this blank line. It's best to remove it to maintain a cleaner YAML file.

Apply this diff to remove the trailing whitespace:

-  
+
🧰 Tools
🪛 yamllint (1.35.1)

[error] 10-10: trailing spaces

(trailing-spaces)

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

9-9: Correct Indentation and Add Newline

Minor YAML formatting issues:

  1. Lines 9 & 33 have an extra space.
  2. There's no newline character at the end of the file.

Apply this diff to fix both:

-       - "terraform"
+      - "terraform"
-       - "terraform"
+      - "terraform"
-        - "^$"
\ No newline at end of file
+        - "^$"
+

Also applies to: 33-33, 45-45

🧰 Tools
🪛 yamllint (1.35.1)

[warning] 9-9: wrong indentation: expected 6 but found 7

(indentation)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 43eb434 and c9f5774.

📒 Files selected for processing (9)
  • .gitignore (1 hunks)
  • Makefile (1 hunks)
  • internal/exec/spinner_utils.go (1 hunks)
  • internal/exec/terraform_outputs.go (3 hunks)
  • tests/fixtures/components/terraform/mock/main.tf (1 hunks)
  • tests/fixtures/scenarios/atmos-functions/atmos.yaml (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)
🧰 Additional context used
🪛 yamllint (1.35.1)
tests/fixtures/scenarios/atmos-functions/atmos.yaml

[error] 10-10: trailing spaces

(trailing-spaces)

tests/test-cases/atmos-functions.yaml

[warning] 9-9: wrong indentation: expected 6 but found 7

(indentation)


[warning] 33-33: wrong indentation: expected 6 but found 7

(indentation)


[error] 45-45: no new line character at the end of file

(new-line-at-end-of-file)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Summary
🔇 Additional comments (23)
internal/exec/spinner_utils.go (6)

1-2: File creation acknowledged.
This new package-level file seems well-scoped for spinner logic.


3-8: Import references look good.
The bubbletea/spinner imports are properly grouped, promoting clarity.


10-13: Struct design note.
Using a value receiver here is acceptable for bubbletea’s update loop. Ensure all fields that need mutation are consistently updated through return statements.


15-17: Init function clarity.
Returning m.spinner.Tick straightforwardly starts the spinner. This is consistent with bubbletea patterns.


19-35: Update function approach.
The switch-case logic is concise and gracefully handles key interrupt signals. Good job stopping on "ctrl+c" or "q".


37-39: View function format.
Printing "\r" for carriage return can behave differently on some terminals. Usually works fine, but keep an eye out for cross-platform quirks.

internal/exec/terraform_outputs.go (11)

14-15: Spinner dependency.
Great to see bubbletea/spinner integrated for user feedback.


221-221: Message string.
The message clarifies which component and stack are queried. This is helpful for debugging.


232-235: Spinner initialization.
Setting a style from theme.Styles.Link is consistent with the rest of the UI approach.


236-242: Non-TTY fallback.
well done gracefully handling no TTY scenario. The fallback to plain output helps in CI environments.


244-248: Program creation logic.
This approach is straightforward, passing the spinner state into the program with optional TTY.


249-258: Goroutine usage.
Spinning a separate goroutine for p.Run allows concurrent Terraform actions. Confirm no concurrency race on shared data.


261-263: Shutdown on error.
Calling p.Quit() before printing the error is good. Make sure to always await the channel so the goroutine ends.


271-273: Additional error path.
Same pattern used for remote state error. Consistency is beneficial.


277-281: Outcome of static outputs.
The logic storing results in the cache is consistent with the rest of the code.


286-288: Error-stop synergy.
Again, p.Quit() ensures the spinner is halted. This is well-handled.


294-302: Final success display.
Terminating the spinner with a checkmark is intuitive. Good user feedback.

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

1-8: Workflow is straightforward.
Sequentially deploying each component helps test cross-component outputs. This approach is clear.

tests/fixtures/components/terraform/mock/main.tf (1)

16-18: Output usage.
Providing outputs for each variable is practical for testing !terraform.output. Good coverage.

Also applies to: 20-22, 24-26

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

1-21: Configuration Looks Good

The overall structure and keys (components, stacks, and logs) are clear and match the intended usage. Great job keeping this organized.

🧰 Tools
🪛 yamllint (1.35.1)

[error] 10-10: trailing spaces

(trailing-spaces)

.gitignore (1)

37-43: Well-Structured Ignore Patterns

These newly added patterns effectively ignore the specified cache and vendor paths, helping keep the repository clean.

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

1-31: Non-Prod Stack Configuration is Clear

The file properly outlines non-production components, each with distinct variables. This approach of referencing outputs across components is a solid practice, demonstrating DRY usage through !terraform.output.

Makefile (1)

58-58: Longer Test Timeout is Reasonable

Extending the timeout to 10 minutes is sensible for complex Terraform operations and spinner interactions.

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.

LGTM

@aknysh aknysh merged commit 56f46d3 into main Jan 24, 2025
44 checks passed
@aknysh aknysh deleted the DEV-2936/terraform-output-spinner branch January 24, 2025 02:05
@mergify mergify bot removed the needs-cloudposse Needs Cloud Posse assistance label Jan 24, 2025
Copy link

These changes were released in v1.154.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.

3 participants