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

Add atmos describe stacks command #133

Merged
merged 19 commits into from Apr 12, 2022
Merged

Add atmos describe stacks command #133

merged 19 commits into from Apr 12, 2022

Conversation

aknysh
Copy link
Member

@aknysh aknysh commented Apr 12, 2022

what

  • Add atmos describe stacks command
  • Allow writing the result to a file by using --file command-line flag
  • Allow formatting the result as YAML or JSON by using --format command-line flag
  • Allow filtering of the result by using the command-line flags: stack, component-types, components, sections
  • Available component sections: backend, backend_type, deps, env, inheritance, metadata, remote_state_backend, remote_state_backend_type, settings, vars

why

  • Command to show stack configs and all the components in the stacks
  • Slice and dice the stack config to show different information about stacks and components

usage

atmos describe stacks
atmos describe stacks --component-types=helmfile
atmos describe stacks --component-types=terraform,helmfile
atmos describe stacks --components=infra/vpc
atmos describe stacks --components=echo-server
atmos describe stacks --components=echo-server,infra/vpc
atmos describe stacks --components=echo-server,infra/vpc --sections=vars
atmos describe stacks --components=echo-server,infra/vpc --sections=vars,settings
atmos describe stacks --components=test/test-component-override-3 --sections=inheritance
atmos describe stacks --components=test/test-component-override-3 --sections=component
atmos describe stacks --components=test/test-component-override-3 --sections=deps
atmos describe stacks --components=test/test-component-override-3 --sections=vars,settings --file=stacks.yaml
atmos describe stacks --components=test/test-component-override-3 --sections=vars,settings --format=json --file=stacks.json
atmos describe stacks --components=test/test-component-override-3 --sections=deps,vars -s=tenant2/ue2/staging

tests

Show all stacks with all the components with all the component sections (Warning: this will dump ALL YAML config for all components for all stacks to the console)

atmos describe stacks

......

tenant2/ue2/staging:
  components:
    terraform:
      test/test-component-override-3:
        backend:
          acl: bucket-owner-full-control
          bucket: eg-ue2-root-tfstate
          dynamodb_table: eg-ue2-root-tfstate-lock
          encrypt: true
          key: terraform.tfstate
          region: us-east-2
          role_arn: null
          workspace_key_prefix: test-test-component
        backend_type: s3
        command: terraform
        component: test/test-component
        deps:
        - catalog/terraform/services/service-1
        - catalog/terraform/services/service-2
        - catalog/terraform/test-component
        - catalog/terraform/test-component-override-3
        - globals/globals
        - globals/tenant2-globals
        - globals/ue2-globals
        - tenant2/ue2/staging
        env:
          TEST_ENV_VAR1: val1-override-3
          TEST_ENV_VAR2: val2-override-3
          TEST_ENV_VAR3: val3-override-3
          TEST_ENV_VAR4: val4-override-3
        inheritance:
        - mixin/test-2
        - mixin/test-1
        - test/test-component-override-2
        - test/test-component-override
        - test/test-component
        metadata:
          component: test/test-component
          inherits:
          - test/test-component-override
          - test/test-component-override-2
          - mixin/test-1
          - mixin/test-2
          terraform_workspace: test-component-override-3-workspace
          type: real
        remote_state_backend:
          acl: bucket-owner-full-control
          bucket: eg-ue2-root-tfstate
          dynamodb_table: eg-ue2-root-tfstate-lock
          encrypt: true
          key: terraform.tfstate
          region: us-east-2
          role_arn: arn:aws:iam::123456789012:role/eg-gbl-root-terraform
          workspace_key_prefix: test-test-component
        remote_state_backend_type: s3
        settings:
          spacelift:
            stack_name_pattern: '{tenant}-{environment}-{stage}-new-component'
            workspace_enabled: false
        vars:
          enabled: true
          environment: ue2
          namespace: eg
          region: us-east-2
          service_1_list:
          - 5
          - 6
          - 7
          service_1_map:
            a: 1
            b: 6
            c: 7
            d: 8
          service_1_name: mixin-2
          service_2_list:
          - 4
          - 5
          - 6
          service_2_map:
            a: 4
            b: 5
            c: 6
          service_2_name: service-2-override-2
          stage: staging
          tenant: tenant2

....

Show only stacks with terraform components

atmos describe stacks --component-types=terraform

Show only stacks with helmfile components

atmos describe stacks --component-types=helmfile

Show only a specific stack with all the components with all the component sections

atmos describe stacks -s=tenant2/ue2/staging

Show only the stacks where a specific component is configured (with all component sections)

atmos describe stacks --components=infra/vpc

Show only the stacks where the specific components are configured (with all component sections)

atmos describe stacks --components=echo-server,infra/vpc

Show only the specific sections for the components in all stacks

atmos describe stacks --components=echo-server,infra/vpc --sections=vars,settings
atmos describe stacks --components=test/test-component-override-3 --sections=inheritance
atmos describe stacks --components=test/test-component-override-3 --sections=component
atmos describe stacks --components=test/test-component-override-3 --sections=deps

Write the result to a file (in YAML format)

atmos describe stacks --sections=vars,settings --file=stacks.yaml

Write the result to a file (in JSON format)

atmos describe stacks --sections=vars,settings --format=json --file=stacks.json

Show all configured stacks (by specifying a non existing component in the filter)

atmos describe stacks --components=none

tenant1/ue2/dev: {}
tenant1/ue2/prod: {}
tenant1/ue2/staging: {}
tenant2/ue2/dev: {}
tenant2/ue2/prod: {}
tenant2/ue2/staging: {}

Show all components in all stacks with just the component names (by specifying a non existing section in the filter)

atmos describe stacks --sections=none

tenant1/ue2/dev:
  components:
    helmfile:
      echo-server: {}
      infra/infra-server: {}
      infra/infra-server-override: {}
    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: {}
tenant1/ue2/prod:
  components:
    helmfile:
      echo-server: {}
      infra/infra-server: {}
      infra/infra-server-override: {}
    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: {}
tenant1/ue2/staging:
  components:
    helmfile:
      echo-server: {}
      infra/infra-server: {}
      infra/infra-server-override: {}
    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: {}
tenant2/ue2/dev:
  components:
    helmfile:
      echo-server: {}
      infra/infra-server: {}
      infra/infra-server-override: {}
    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: {}
tenant2/ue2/prod:
  components:
    helmfile:
      echo-server: {}
      infra/infra-server: {}
      infra/infra-server-override: {}
    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: {}
tenant2/ue2/staging:
  components:
    helmfile:
      echo-server: {}
      infra/infra-server: {}
      infra/infra-server-override: {}
    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: {}

Show only a specific component in all stacks with just the component name (by specifying a non existing section in the filter) - this shows in which stacks the specified component exists

atmos describe stacks --components=infra/vpc --sections=none

tenant1/ue2/dev:
  components:
    terraform:
      infra/vpc: {}
tenant1/ue2/prod:
  components:
    terraform:
      infra/vpc: {}
tenant1/ue2/staging:
  components:
    terraform:
      infra/vpc: {}
tenant2/ue2/dev:
  components:
    terraform:
      infra/vpc: {}
tenant2/ue2/prod:
  components:
    terraform:
      infra/vpc: {}
tenant2/ue2/staging:
  components:
    terraform:
      infra/vpc: {}

@aknysh aknysh added the patch A minor, backward compatible change label Apr 12, 2022
@aknysh aknysh requested a review from a team as a code owner April 12, 2022 15:07
@aknysh aknysh self-assigned this Apr 12, 2022
@aknysh aknysh requested a review from a team as a code owner April 12, 2022 15:07
Nuru
Nuru previously approved these changes Apr 12, 2022
Copy link
Sponsor Contributor

@Nuru Nuru left a comment

Choose a reason for hiding this comment

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

I would like to be able to filter components by type (Terraform, Helm, other). Can be a follow-up if that is too big a change.

See comment about checkStack. Not sure if it is a bug or just a documentation issue.

internal/exec/utils.go Outdated Show resolved Hide resolved
@aknysh aknysh requested a review from Nuru April 12, 2022 20:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
patch A minor, backward compatible change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants