Skip to content

fix: Update workspace list implementation to tolerate warnings present in stdout output#562

Open
SarahFrench wants to merge 1 commit intomainfrom
pss/tolerate-warnings-in-stdout-workspace-list
Open

fix: Update workspace list implementation to tolerate warnings present in stdout output#562
SarahFrench wants to merge 1 commit intomainfrom
pss/tolerate-warnings-in-stdout-workspace-list

Conversation

@SarahFrench
Copy link
Member

@SarahFrench SarahFrench commented Jan 26, 2026

Note: This is likely to be flaky once warnings start being present in the command's stdout output. The best resolution is to add machine-readable output support to the workspace commands! I'm working on this.

Related Issue

N/A

Description

I'm proposing some changes to the workspace list command to migrate it from using cli.Ui to view.View when rendering human-readable output. The command doesn't support machine-readable output, yet.

That migration process will cause warning diagnostics to be sent to stdout instead of stderr, which is what happens currently. Due to this, terraform-exec is written to parse workspace list's human-readable output under the assumption that stdout will only include the list of workspaces. This assumption is currently correct but might not be in future.

If a warning is present in stdout the current parsing code will assume every non-empty line is a workspace name.

This PR introduces some light filtering of non-empty lines to determine if the string is part of a warning or a workspace name. This is based on how Terraform validates workspace names; URL escaping.

Rollback Plan

  • If a change needs to be reverted, we will roll out an update to the code within 7 days.

Changes to Security Controls

N/A

…ent in stdout output

This is likely to be flaky and the best resolution is to add machine-readable output support to the workspace commands!
@SarahFrench
Copy link
Member Author

This change is motivated by this update to Terraform Core, but it can be merged independently of that PR. Due to that I'm opening this PR for review.

@SarahFrench SarahFrench marked this pull request as ready for review January 26, 2026 18:29
@SarahFrench SarahFrench requested review from a team as code owners January 26, 2026 18:29
Copy link
Member

@radeksimko radeksimko left a comment

Choose a reason for hiding this comment

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

I don't really like processing the output like that but aside from what you already suggested and are working on (JSON output) I don't think we have any better options sadly. 😹 😭

current = line
}

if line != url.PathEscape(line) {
Copy link
Member

Choose a reason for hiding this comment

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

oof, this is precisely why we need JSON output. Kinda regret we even added support for this command here so early. 😂 😭

Copy link
Member Author

Choose a reason for hiding this comment

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

FWIW I felt very dirty adding this code 😭 , but I'm working on JSON output!

@SarahFrench
Copy link
Member Author

I'll save merging this for when the JSON output for workspace list is further along. Potentially this PR could be merged alongside a change to add -json support here in terraform-exec.

@radeksimko
Copy link
Member

I'll save merging this for when the JSON output for workspace list is further along. Potentially this PR could be merged alongside a change to add -json support here in terraform-exec.

I think that merging both at the same time makes sense but keep in mind that we tend to maintain some level of compatibility within terraform-exec and so like with other commands with discussed, this implies initially introducing the JSON version as WorkspaceListJSON and later, in terraform-exec v1 making WorkspaceList consume JSON by default and phasing out the *JSON suffixed variation.

All that is to say that this patch will stay around until at least v1 and JSON cannot directly replace it yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants