Skip to content

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

Merged
SarahFrench merged 2 commits into
mainfrom
pss/tolerate-warnings-in-stdout-workspace-list
Oct 27, 2026
Merged

SarahFrench merged 2 commits into
mainfrom
pss/tolerate-warnings-in-stdout-workspace-list

Conversation

@SarahFrench

@SarahFrench SarahFrench commented Jan 26, 2026 •

Copy link
Copy Markdown
Member

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

@SarahFrench

Copy link
Copy Markdown
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
radeksimko
radeksimko previously approved these changes Jan 28, 2026

@radeksimko radeksimko left a comment

Copy link
Copy Markdown
Member

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. 😹 😭

Comment thread tfexec/workspace_list.go
current = line
}

if line != url.PathEscape(line) {

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

…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
SarahFrench force-pushed the pss/tolerate-warnings-in-stdout-workspace-list branch from a98340c to 7a47383 Compare October 26, 2026 18:58
@SarahFrench

Copy link
Copy Markdown
Member Author

I found some evidence of terraform-plugin-testing falling over due to warnings in the output from running tf.WorkspaceList internally, hence me returning to this PR:

Step 1/1 error running state store tests: After init, expected the "default" workspace to be created: Expected workspaces to be []string{"default"}, got: []string{"Warning: GetStates not implemented", "Warning: test warning", "default", "test warning from the GetStates method", "test warning from the Schema method"}

@SarahFrench

Copy link
Copy Markdown
Member Author

Looks like the failing tests are due to the mismatch between hashicorp/terraform and hashicorp/terraform-exec - solved by #620 I hope.

@radeksimko

Copy link
Copy Markdown
Member

It looks like the E2E test failure is unrelated to this PR but will need addressing

=== RUN   TestGraph/basic-refs/heads/main
    util_test.go:191: [INFO] running Terraform command: /tmp/hc-install-terraform-5de495591556532a56499c23770036530a7aa90a3076247594/terraform init -no-color -input=false -backend=true -get=true -upgrade=false
    util_test.go:191: [INFO] running Terraform command: /tmp/hc-install-terraform-5de495591556532a56499c23770036530a7aa90a3076247594/terraform apply -no-color -auto-approve -input=false -lock=true -parallelism=10 -refresh=true
    util_test.go:191: [INFO] running Terraform command: /tmp/hc-install-terraform-5de495591556532a56499c23770036530a7aa90a3076247594/terraform graph
    graph_test.go:34: Graph output does not match:   (
          	"""
          	... // 4 identical lines
          	}
          	
        + 	
          	"""
          )
--- FAIL: TestGraph (0.65s)
    --- FAIL: TestGraph/basic-refs/heads/main (0.65s)

@SarahFrench
SarahFrench merged commit f1b461b into main Oct 27, 2026
304 of 319 checks passed
@SarahFrench
SarahFrench deleted the pss/tolerate-warnings-in-stdout-workspace-list branch October 27, 2026 12:41
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