Skip to content

custom cli commands: Cannot access outputted plan file or atmos workspace name #215

Open

Description

@nitrocode

Have a question? Please checkout our Slack Community or visit our Slack Archive.

Slack Community

Describe the Feature

I cannot seem to get the atmos workspace name in the custom atmos commands

commands:
  - name: tf
    description: Execute terraform commands
    commands:
      - name: plan
        arguments:
          - name: component
            description: Name of the component
        flags:
          - name: stack
            shorthand: s
            description: Name of the stack
            required: true
        env:
          - key: ATMOS_COMPONENT
            value: "{{ .Arguments.component }}"
          - key: ATMOS_STACK
            value: "{{ .Flags.stack }}"
        steps:
          - ATMOS_WORKSPACE=$(atmos describe component $ATMOS_COMPONENT --stack $ATMOS_STACK | yq .workspace)

Error

⨠ atmos infracost plan eks/cluster-blue --stack plat-ue2-sandbox

Using ENV vars:
ATMOS_COMPONENT=eks/cluster-blue
ATMOS_STACK=plat-ue2-sandbox

Executing command:
ATMOS_WORKSPACE=$(atmos describe component eks/cluster-blue --stack plat-ue2-sandbox | yq .workspace)
exec: "ATMOS_WORKSPACE=$(atmos": executable file not found in $PATH

I also tried quoting the entire step and it resulted in the same error.

I tried prefixing the string with export and it resulted in error.

exec: "export": executable file not found in $PATH

Expected Behavior

Run the command correctly or retrieve the atmos workspace

Use Case

I'd like to use the atmos workspace to access the planfile so I can create custom cli commands to run infracost or other tools on the plan file

Describe Ideal Solution

The ideal solution would be to use the choria-io library directly https://github.com/choria-io/appbuilder

so we can take advantage of the type: exec and script spec

      flags:
        - name: stack
          description: Name of the stack
          required: true
      type: exec
      script: |
        set -x
        ATMOS_WORKSPACE=$(atmos describe component $ATMOS_COMPONENT --stack $ATMOS_STACK | yq .workspace)

Previous discussion: https://github.com/cloudposse/atmos/discussions/166

Alternatives Considered

Alternative 1

I considered concatenating the $ATMOS_STACK and $ATMOS_COMPONENT but this would not work because the file is

plat-ue2-sandbox-eks-cluster-blue.planfile

If I were to concatenate the stack and component, I would get this file name

plat-ue2-sandbox-eks-cluster/blue.planfile

And there is no way to do an in-line script (like in choria-io) where I can replace the / with a - to get the correct workspace / plan file name.

Alternative 2

  1. Write a shell script
  2. Save the shell script to a PATH directory so it's findable in any directory
  3. Run the shell script from the atmos custom cli steps

Additional Context

N/A

Activity

  1. thejrose1984 commented on May 31, 2026

    @thejrose1984
    Contributor

    This appears to be resolved on current main ✅

    I tried to reproduce this against main (commit 30238462, built locally) and the originally-reported error no longer occurs — custom-command steps are now run through a real shell interpreter, so VAR=$(...), pipes, export, and command substitution all work.

    Root cause (now fixed): steps are no longer word-split and exec'd directly. The step type defaults to shell and runs via ExecuteShell → ShellRunner, which parses/interprets the command with the in-process shell mvdan.cc/sh/v3 (pkg/utils/shell_utils.go). Steps also now accept an explicit type: field (shell / atmos / extended types), which partially covers the type: exec / script request from the issue.

    Reproduction — a custom command mirroring the report, including the /→- workspace-name conversion from "Alternative 1":

    commands:
      - name: repro
        arguments:
          - name: component
            description: Component name
        flags:
          - name: stack
            shorthand: s
            required: true
        env:
          - key: ATMOS_COMPONENT
            value: "{{ .Arguments.component }}"
          - key: ATMOS_STACK
            value: "{{ .Flags.stack }}"
        steps:
          - 'COMPUTED=$(echo "$ATMOS_STACK-$ATMOS_COMPONENT" | tr "/" "-"); echo "workspace=$COMPUTED"'
          - 'export FOO=bar; echo "export works: $FOO"'
    $ atmos repro eks/cluster-blue --stack plat-ue2-sandbox
    workspace=plat-ue2-sandbox-eks-cluster-blue
    export works: bar
    # exit code 0

    The exact constructs that previously failed (ATMOS_WORKSPACE=$(atmos ...), export, pipes) now succeed, and the inline /→- conversion the reporter wanted works too.

    This looks like a good candidate to close as resolved. 🙏

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions