8000 fix: Don't use terraform workspace in `terraform.output` when backend is `http` by astephanh · Pull Request #1268 · cloudposse/atmos · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

8000 fix: Don't use terraform workspace in terraform.output when backend is http #1268

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

Merged
merged 8 commits into from
Jun 3, 2025

Conversation

astephanh
Copy link
Contributor
@astephanh astephanh commented May 26, 2025

This fix disables terraform workspace commands for !terraform.output if backend_type is http.

what

This change checks if terraform http backend is used, to skip terraform workspace commands in !terraform.output

why

Using http backend for remote state will end in an error, because atmos is still trying to select a workspace.

❯ atmos terraform plan  hello-world -s plat-acme-main
Initializing the backend...

Successfully configured the backend "http"! Terraform will automatically
use this backend unless the backend configuration changes.
Initializing modules...
Initializing provider plugins...
- Reusing previous version of hashicorp/null from the dependency lock file
- Using previously-installed hashicorp/null v3.2.4

Terraform has been successfully initialized!
workspaces not supported
Failed to get configured named states: workspaces not supported
 Error

exit status 1

references

Summary by CodeRabbit

  • Bug Fixes
    • Resolved an issue where workspace creation and selection were incorrectly performed for the "http" backend type during Terraform execution. Workspace operations are now skipped for this backend, improving compatibility with different backend configurations.

@astephanh astephanh requested a review from a team as a code owner May 26, 2025 12:50
@mergify mergify bot added the triage Needs triage label May 26, 2025
Copy link
Contributor
coderabbitai bot commented May 26, 2025
📝 Walkthrough

"""

Walkthrough

A conditional check was added to skip Terraform workspace creation and selection when the backend type is set to "http". The workspace-related operations are now only executed if the backend type is not "http", while the rest of the function remains unchanged.

Changes

File(s) Change Summary
internal/exec/terraform_outputs.go Added conditional to bypass workspace creation/selection if backend type is "http".
internal/exec/terraform.go Updated condition to include check for backend_type != "http" before running workspace commands; added fallback to create workspace if selection fails.

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant TerraformOutputs
    participant Terraform

    Caller->>TerraformOutputs: Execute function
    alt Backend type != "http"
        TerraformOutputs->>Terraform: WorkspaceNew()
        TerraformOutputs->>Terraform: WorkspaceSelect()
    else Backend type == "http"
        Note right of TerraformOutputs: Skip workspace operations
    end
    TerraformOutputs->>Terraform: terraform output
    Terraform->>TerraformOutputs: Return outputs
    TerraformOutputs->>Caller: Return processed outputs
Loading

Suggested labels

patch
"""

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @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.

8000

Actionable comments posted: 1

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 1953e23 and 58b8f42.

📒 Files selected for processing (1)
  • internal/exec/terraform_outputs.go (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Summary
🔇 Additional comments (1)
internal/exec/terraform_outputs.go (1)

225-253: Good fix for HTTP backend workspace issue.

The conditional logic correctly skips workspace operations when using HTTP backend, addressing the "workspaces not supported" error mentioned in the PR.

🧰 Tools
🪛 golangci-lint (1.64.8)

[error] 225-225: File is not properly formatted

(gofumpt)


[error] 252-252: File is not properly formatted

(gofumpt)

astephanh added 2 commits May 26, 2025 15:10
This fix disables terraform workspace commands for !terraform.output if
backend_type is http.
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

♻️ Duplicate comments (1)
internal/exec/terraform_outputs.go (1)

224-225: Good job implementing the safe type assertion pattern.

The comma-ok idiom properly handles nil values and prevents runtime panics. This addresses the previous concern raised in the review.

🧰 Tools
🪛 golangci-lint (1.64.8)

[error] 224-224: File is not properly formatted

(gofumpt)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 58b8f42 and 1cd5e52.

📒 Files selected for processing (2)
  • internal/exec/terraform.go (1 hunks)
  • internal/exec/terraform_outputs.go (2 hunks)
🧰 Additional context used
🪛 golangci-lint (1.64.8)
internal/exec/terraform.go

[error] 440-440: File is not properly formatted

(gofumpt)

internal/exec/terraform_outputs.go

[error] 224-224: File is not properly formatted

(gofumpt)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Summary

coderabbitai[bot]
coderabbitai bot previously approved these changes May 26, 2025
@mergify mergify bot removed the triage Needs triage label May 26, 2025
@osterman osterman added the patch A minor, backward compatible change label May 26, 2025
@osterman osterman changed the title fix: Don't use terraform workspace in terraform.output when backend is http fix: Don't use terraform workspace in terraform.output when backend is http May 26, 2025
Copy link
codecov bot commented May 26, 2025

Codecov Report

Attention: Patch coverage is 77.35849% with 12 lines in your changes missing coverage. Please review.

Project coverage is 49.32%. Comparing base (6462315) to head (191085b).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
internal/exec/terraform.go 67.85% 6 Missing and 3 partials ⚠️
internal/exec/terraform_outputs.go 88.00% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1268      +/-   ##
==========================================
+ Coverage   49.25%   49.32%   +0.06%     
==========================================
  Files         234      234              
  Lines       25576    25581       +5     
==========================================
+ Hits        12598    12618      +20     
+ Misses      11318    11299      -19     
- Partials     1660     1664       +4     
Flag Coverage Δ
unittests 49.32% <77.35%> (+0.06%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@aknysh aknysh added no-release Do not create a new release (wait for additional code changes) and removed patch A minor, backward compatible change labels May 30, 2025
coderabbitai[bot]
coderabbitai bot previously approved these changes Jun 2, 2025
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)

449-451: Clean implementation of HTTP backend check.

The conditional logic correctly prevents workspace commands from executing when using HTTP backends, which aligns perfectly with the PR objectives. The refactored structure is much cleaner than the previous complex nested condition.

However, there's a minor formatting issue to address.

-	if info.SubCommand != "init" && !(info.SubCommand == "workspace" && info.SubCommand2 != "") {
-		// Don't use workspace commands in http backend
-		if info.ComponentBackendType != "http" {
+	if info.SubCommand != "init" && !(info.SubCommand == "workspace" && info.SubCommand2 != "") {
+		// Don't use workspace commands in http backend
+		if info.ComponentBackendType != "http" {
🧰 Tools
🪛 golangci-lint (1.64.8)

[error] 451-451: unnecessary leading newline

(whitespace)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 77faabc and 191085b.

📒 Files selected for processing (1)
  • internal/exec/terraform.go (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
internal/exec/terraform.go (2)
internal/exec/shell_utils.go (1)
  • ExecuteShellCommand (21-75)
pkg/schema/schema.go (1)
  • Command (568-578)
🪛 golangci-lint (1.64.8)
internal/exec/terraform.go

[error] 451-451: unnecessary leading newline

(whitespace)

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

453-494: Solid workspace selection and creation logic.

The workspace handling implementation is well-structured:

  • Properly checks for TF_WORKSPACE environment variable
  • Implements appropriate fallback logic when workspace selection fails
  • Correctly handles exit code 1 to distinguish between "workspace doesn't exist" and other errors
  • Maintains consistent error redirection handling

The addition of workspace creation as a fallback when selection fails with exit code 1 is a thoughtful improvement that makes the workspace handling more robust.

@aknysh aknysh added minor New features that do not break anything and removed no-release Do not create a new release (wait for additional code changes) labels Jun 3, 2025
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.

thanks @astephanh

@aknysh aknysh merged commit 83a5cc3 into cloudposse:main Jun 3, 2025
253 of 259 checks passed
Copy link
github-actions bot commented Jun 3, 2025

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