Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Command for Listing Stacks #395

Closed
RoseSecurity opened this issue Jun 30, 2023 · 2 comments
Closed

Command for Listing Stacks #395

RoseSecurity opened this issue Jun 30, 2023 · 2 comments

Comments

@RoseSecurity
Copy link
Contributor

Describe the Feature

Would it be possible to incorporate a command for listing available stacks? I have been utilizing atmos describe stacks | grep -e '^\S' | sed s/://g to get a complete list of stacks, but if this could be incorporated as a command, it would be an awesome feature!

I am sure there is a more eloquent way of doing it, but even if the output of the atmos describe was passed to another function for parsing, this would be beneficial.

// describeStacksCmd describes configuration for stacks and components in the stacks
var describeStacksCmd = &cobra.Command{
	Use:                "stacks",
	Short:              "Execute 'describe stacks' command",
	Long:               `This command shows configuration for atmos stacks and components in the stacks: atmos describe stacks [options]`,
	FParseErrWhitelist: struct{ UnknownFlags bool }{UnknownFlags: false},
	Run: func(cmd *cobra.Command, args []string) {
		err := e.ExecuteDescribeStacksCmd(cmd, args)
		if err != nil {
			u.LogErrorAndExit(err)
		}
	},
}

Expected Behavior

When the command is ran, the terminal output would appear as the following:

(HOST) infra ⨠ atmos list stacks

dev-use1-admin
dev-usw2-admin
dev-use1-net
dev-usw2-net

Use Case

It is difficult to know what stacks are available

Describe Ideal Solution

Please see above

Alternatives Considered

No response

Additional Context

No response

@aknysh
Copy link
Member

aknysh commented Jun 30, 2023

@RoseSecurity thank you for testing Atmos and opening this issue.

The command atmos describe stacks support many different parameters for filtering the stacks, see https://atmos.tools/cli/commands/describe/stacks

We agree that the filtering is not ideal, and we'll improve it to make it easier to filter for anything and output in any format. For example. output just the stack names, which is not supported now as you described above, but here is what supported and you can use it to get the stack names with a little help from jq or yq.

atmos describe stacks --sections none --component-types terraform

If you use --sections none parameter, you can get ALL the stack names with ALL the components in the stacks:

tenant2-ue2-dev:
  components:
    terraform:
      infra/vpc: {}
      mixin/test-1: {}
      mixin/test-2: {}
      test/test-component: {}
      test/test-component-override: {}
      test/test-component-override-2: {}
      test/test-component-override-3: {}
      top-level-component1: {}
      vpc: {}
tenant2-ue2-prod:
  components:
    terraform:
      infra/vpc: {}
      infrastructure-tenant2: {}
      mixin/test-1: {}
      mixin/test-2: {}
      spacelift-defaults: {}
      test/test-component: {}
      test/test-component-override: {}
      test/test-component-override-2: {}
      test/test-component-override-3: {}
      top-level-component1: {}
      vpc: {}
tenant2-ue2-staging:
  components:
    terraform:
      infra/vpc: {}
      mixin/test-1: {}
      mixin/test-2: {}
      test/test-component: {}
      test/test-component-override: {}
      test/test-component-override-2: {}
      test/test-component-override-3: {}
      top-level-component1: {}
      vpc: {}

To see what stacks have a particular component, you can run:

atmos describe stacks --sections none --components top-level-component1
tenant1-ue2-dev:
  components:
    terraform:
      top-level-component1: {}
tenant1-ue2-prod:
  components:
    terraform:
      top-level-component1: {}
tenant1-ue2-staging:
  components:
    terraform:
      top-level-component1: {}
tenant2-ue2-dev:
  components:
    terraform:
      top-level-component1: {}
tenant2-ue2-prod:
  components:
    terraform:
      top-level-component1: {}
tenant2-ue2-staging:
  components:
    terraform:
      top-level-component1: {}

To get a particular section for the component, e.g. vars, you can add the filter fro the sections, like so:

atmos describe stacks --sections vars --components top-level-component1
tenant2-ue2-dev:
  components:
    terraform:
      top-level-component1:
        vars:
          enabled: true
          environment: ue2
          namespace: cp
          region: us-east-2
          service_1_name: top-level-service-1
          service_2_name: top-level-service-2
          stage: dev
          tenant: tenant2
tenant2-ue2-prod:
  components:
    terraform:
      top-level-component1:
        vars:
          enabled: true
          environment: ue2
          namespace: cp
          region: us-east-2
          service_1_name: top-level-service-1
          service_2_name: top-level-service-2
          stage: prod
          tenant: tenant2
tenant2-ue2-staging:
  components:
    terraform:
      top-level-component1:
        vars:
          enabled: true
          environment: ue2
          namespace: cp
          region: us-east-2
          service_1_name: top-level-service-1
          service_2_name: top-level-service-2
          stage: staging
          tenant: tenant2

So, although the filtering is not perfect and we'll be improving it, you can use the --stack, --components, and --sections parameters to filter by stacks, components, and any sections of the component configs.

References:

@RoseSecurity
Copy link
Contributor Author

Thank you for this informative answer @aknysh! I'm excited to see how tool continues to develop and thank you for your assistance with those useful commands.

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

No branches or pull requests

2 participants