Skip to content

Add --redirect-stderr flag to atmos commands - #322

Merged
Andriy Knysh (aknysh) merged 11 commits into
masterfrom
redirect-stderr-to-stdout
Feb 13, 2023
Merged

Andriy Knysh (aknysh) merged 11 commits into
masterfrom
redirect-stderr-to-stdout

Conversation

@aknysh

@aknysh Andriy Knysh (aknysh) commented Feb 12, 2023 •

Copy link
Copy Markdown
Member

what

  • Add --redirect-stderr flag to atmos commands
  • If --redirect-stderr flag is not passed, always redirect stderr to stdout for terraform workspace select command

why

  • The flag specifies the file descriptor to redirect stderr to when atmos executes subcommands like atmos terraform and atmos helmfile
  • Errors can be redirected to any file or any standard file descriptor (including /dev/null and /dev/stdout)
  • Useful in GitHub actions to prevent failures when any error sent to stderr makes the action fail

examples

atmos terraform plan test/test-component-override-2 -s tenant1-ue2-dev --redirect-stderr /dev/stdout
atmos terraform plan test/test-component-override -s tenant1-ue2-dev --redirect-stderr ./errors.txt

atmos terraform apply test/test-component-override-2 -s tenant1-ue2-dev --redirect-stderr /dev/stdout
atmos terraform apply test/test-component-override -s tenant1-ue2-dev --redirect-stderr ./errors.txt

atmos terraform destroy test/test-component-override-2 -s tenant1-ue2-dev --redirect-stderr /dev/stdout
atmos terraform destroy test/test-component-override -s tenant1-ue2-dev --redirect-stderr /dev/null

mos terraform workspace test/test-component-override-3 -s tenant1-ue2-dev --redirect-stderr /dev/null
atmos terraform workspace test/test-component-override-3 -s tenant1-ue2-dev --redirect-stderr /dev/stdout
atmos terraform workspace test/test-component-override-3 -s tenant1-ue2-dev --redirect-stderr ./errors.txt

test

atmos terraform plan test/test-component-override-3 -s tenant1-ue2-dev
Executing command:
/usr/local/bin/terraform workspace select test-component-override-3-workspace

# This is an error generated by terraform and sent to `stderror`
Workspace "test-component-override-3-workspace" doesn't exist.

You can create this workspace with the "new" subcommand.

Executing command:
/usr/local/bin/terraform workspace new test-component-override-3-workspace
Created and switched to workspace "test-component-override-3-workspace"!
atmos terraform plan test/test-component-override-3 -s tenant1-ue2-dev --redirect-stderr /dev/null
Executing command:
/usr/local/bin/terraform workspace select test-component-override-3-workspace

Executing command:
/usr/local/bin/terraform workspace new test-component-override-3-workspace
Created and switched to workspace "test-component-override-3-workspace"!

@aknysh
Andriy Knysh (aknysh) temporarily deployed to preview February 12, 2023 03:36 — with GitHub Actions Inactive
@aknysh
Andriy Knysh (aknysh) temporarily deployed to preview February 12, 2023 03:39 — with GitHub Actions Inactive
@mcalhoun

Matt Calhoun (mcalhoun) commented Feb 13, 2023 •

Copy link
Copy Markdown
Contributor

Andriy Knysh (@aknysh) This implementation is slightly different from what I had in mind...specifically, I was only expecting atmos to "ignore" writing to stderr in the case of selecting a workspace that doesn't exist, as we then immediately create the missing workspace. This case, specifically, is what GitHub Actions is showing as an error.

With your proposed implementation, If we redirect all of stderr to a file, we'd then have to parse that file and somehow figure out to ignore just the select workspace error, but raise an error if any other error occurred. Also, I don't think this command, as implemented, actually brings any additional value over >errors.txt 2>&1 unless I'm missing something?

@aknysh

Andriy Knysh (aknysh) commented Feb 13, 2023 •

Copy link
Copy Markdown
Member Author

Andriy Knysh (@aknysh) This implementation is slightly different from what I had in mind...specifically, I was only expecting atmos to "ignore" writing to stderr in the case of selecting a workspace that doesn't exist, as we then immediately create the missing workspace. This case, specifically, is what GitHub Actions is showing as an error.

With your proposed implementation, If we redirect all of stderr to a file, we'd then have to parse that file and somehow figure out to ignore just the select workspace error, but raise an error if any other error occurred. Also, I don't think this command, as implemented, actually brings any additional value over >errors.txt 2>&1 unless I'm missing something?

This covers the workspace as well.
Since we want to do everything generically, this is implemented like this to cover many other cases (otherwise, we'll have a bunch of code covering some exceptions to the rule).

Specifically for workspace, you can do the following:

atmos terraform apply xxx -s yyy --redirect-stderr zzzz

this will redirect the errors for the workspace as well.

Or you can do the following (if you don't want to redirect the errors, if any, from other TF commands):

atmos terraform workspace xxx -s yyy --redirect-stderr zzzz
atmos terraform apply xxx -s yyy

this will create a new workspace and redirect the errors to stderr, and then terraform apply will just select the already created workspace


I've also added

workspaceSelectRedirectStdErr := "/dev/stdout"

// If `--redirect-stderr` flag is not passed, always redirect `stderr` to `stdout` for `terraform workspace select` command
if info.RedirectStdErr != "" {
	workspaceSelectRedirectStdErr = info.RedirectStdErr
}

err = ExecuteShellCommand(
	info.Command,
	[]string{"workspace", "select", info.TerraformWorkspace},
	componentPath,
	info.ComponentEnvList,
	info.DryRun,
	true,
	workspaceSelectStdErr,
)

so for normal operations, you don't need to use --redirect-stderr since terraform workspace select will redirect it to stdout automatically

@aknysh
Andriy Knysh (aknysh) temporarily deployed to preview February 13, 2023 15:14 — with GitHub Actions Inactive
@mcalhoun

Copy link
Copy Markdown
Contributor

This updated implementation LGTM, thanks Andriy Knysh (@aknysh)

@mcalhoun Matt Calhoun (mcalhoun) left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM!

@aknysh
Andriy Knysh (aknysh) merged commit ee7ab21 into master Feb 13, 2023
@aknysh
Andriy Knysh (aknysh) deleted the redirect-stderr-to-stdout branch February 13, 2023 15:42
Erik Osterman (Cloud Posse) (osterman) added a commit that referenced this pull request Oct 23, 2026
Raise pnpm overrides to patched releases:
- dompurify ^3.4.17 (#327, #328, #329)
- launch-editor ^2.14.2 (#324, #325, #326)
- follow-redirects ^1.16.1 (#322, #323)

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Hill Patel (STiFLeR7) pushed a commit to STiFLeR7/atmos that referenced this pull request Oct 29, 2026
…e#3502)

* fix: upgrade Node.js to 24.22.1 for October 2026 security releases

Node.js 24.22.1 fixes CVE-2026-111497 (Brotli OOB write / RCE),
CVE-2026-105483 and CVE-2026-106069 (TLS hostname verification
bypasses), CVE-2026-105482 (dns.resolve NUL truncation), and several
medium/low CVEs.

- pkg/auth/providers/aws: bump the Node runtime Atmos downloads for the
  SAML Playwright driver from 24.18.0 to 24.22.1.
- website/.nvmrc: move off EOL Node 25.1.0 (unpatched) to 24.22.1 LTS.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

* fix(security): remediate 7 website Dependabot alerts

Raise pnpm overrides to patched releases:
- dompurify ^3.4.17 (cloudposse#327, cloudposse#328, cloudposse#329)
- launch-editor ^2.14.2 (cloudposse#324, cloudposse#325, cloudposse#326)
- follow-redirects ^1.16.1 (cloudposse#322, cloudposse#323)

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

* fix(security): bump Go to 1.26.10 for GO-2026-6809

Go 1.26.10 makes crypto/x509 distrust compromised intermediate
certificates (CVE-2026-111943), which govulncheck reports Atmos calls.

The Windows exception-reserve CI workaround is version-locked, so
re-pin it to go1.26.10. golang/go#81238 is still open, and
src/runtime/stack.go is byte-identical between 1.26.9 and 1.26.10, so
the verified source SHA256 and the replacement are unchanged.

Add a fix log covering this PR's Node, Go, and npm upgrades.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

* docs: say pnpm overrides in the security upgrades fix log

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>

* fix(security): remediate x/net and follow-redirects advisories

Bump golang.org/x/net to v0.62.0 (GO-2026-6866, GO-2026-6860) and pin
follow-redirects to 1.16.1 in the cdk-terraform example via an npm override
(Dependabot 336, 337). Regenerate NOTICE.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>

* fix: tidy go.mod after merging origin/main

Drop duplicate pre-merge requirements and the stale gocloud.dev pin comment
(main moved to v0.46.0 and removed the pin), keeping the x/net security bumps.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>

* fix(plugins): bump auth-secrets to 1.0.1 for changed go.mod build input

The x/net security bump changes go.mod, a declared build input for
auth-secrets, so the plugin release check requires a version increase.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>

* fix(casts): stage screengrabs beside the output to avoid EXDEV

The generator recorded casts into the system temp directory and then called
os.replace into website/static, which fails with 'Invalid cross-device link'
on CI runners where /tmp and the workspace are on different filesystems.
Stage inside the output directory so the final move is always same-filesystem.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>

* fix: tidy go.mod after merging origin/main

Remove the duplicate gocloud.dev requirement left by the merge.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>

This branch was previously deployed

1 inactive deployment
preview — 0003aa4e Deployed Feb 13, 2023 by aknysh
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.

2 participants