cloudposse / cloudposse/atmos

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

Open
#215 1 comment 0 reactions 0 assignees View on GitHub
bug
Dominant language
Go
Stars
1.4k
Forks
175
Avg merge
2d 3h
Merged PRs (30d)
134

Description

Have a question? Please checkout our [Slack Community](https://slack.cloudposse.com) or visit our [Slack Archive](https://archive.sweetops.com/).

[![Slack Community](https://slack.cloudposse.com/badge.svg)](https://slack.cloudposse.com)

## Describe the Feature

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

```yaml
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

```sh
⨠ 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

```yaml
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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.