github cloudposse/atmos v1.4.22

latest releases: v1.105.0, v1, v1.104.0...
2 years ago

what

  • Add ATMOS_CLI_CONFIG_PATH ENV var
  • Detect more YAML stack misconfigurations
  • Add functionality to define atmos custom CLI commands

why

  • ATMOS_CLI_CONFIG_PATH ENV var allows specifying the location of atmos.yaml CLI config file. This is useful for CI/CD environments (e.g. Spacelift) where an infrastructure repository gets loaded into a custom path and atmos.yaml is not in the locations where atmos expects to find it (no need to copy atmos.yaml into /usr/local/etc/atmos/atmos.yaml)

  • Detect more YAML stack misconfigurations, e.g. when the same tenant/environment/stage is defined in more than one top-level YAML stack config file (directly or via imports).

    For example, if the same var.tenant = tenant1 is specified for tenant1-ue2-dev and tenant2-ue2-dev stacks, the
    command atmos describe component test/test-component-override -s tenant1-ue2-dev will throw this error

    Searching for stack config where the component 'test/test-component-override' is defined
    Found config for the component 'test/test-component-override' for the stack 'tenant1-ue2-dev' in the file 'tenant1/ue2/dev'
    Found config for the component 'test/test-component-override' for the stack 'tenant1-ue2-dev' in the file 'tenant2/ue2/dev'
    
    Found duplicate config for the component 'test/test-component-override' for the stack 'tenant1-ue2-dev' in the files: tenant1/ue2/dev, tenant2/ue2/dev.
    Check that all context variables in the stack name pattern '{tenant}-{environment}-{stage}' are correctly defined in the files and not duplicated.
    Check that imports are valid.
    
  • Allow extending atmos with custom commands. Custom commands can be defined in atmos.yaml CLI config file. Custom commands support subcommands at any level (e.g. atmos my-command subcommand1 suncommand2 argument1 argument2 flag1 flag2)

# Custom CLI commands
commands:
  - name: tf
    description: Execute terraform commands
    # subcommands
    commands:
      - name: plan
        description: This command plans terraform components
        arguments:
          - name: component
            description: Name of the component
        flags:
          - name: stack
            shorthand: s
            description: Name of the stack
            required: true
        env:
          - key: ENV_VAR_1
            value: ENV_VAR_1_value
          - key: ENV_VAR_2
            # `valueCommand` is an external command to execute to get the value for the ENV var
            # Either 'value' or 'valueCommand' can be specified for the ENV var, but not both
            valueCommand: echo ENV_VAR_2_value
        # steps support Go templates
        steps:
          - atmos terraform plan {{ .Arguments.component }} -s {{ .Flags.stack }}
  - name: terraform
    description: Execute terraform commands
    # subcommands
    commands:
      - name: provision
        description: This command provisions terraform components
        arguments:
          - name: component
            description: Name of the component
        flags:
          - name: stack
            shorthand: s
            description: Name of the stack
            required: true
        # ENV var values support Go templates
        env:
          - key: ATMOS_COMPONENT
            value: "{{ .Arguments.component }}"
          - key: ATMOS_STACK
            value: "{{ .Flags.stack }}"
        steps:
          - atmos terraform plan $ATMOS_COMPONENT -s $ATMOS_STACK
          - atmos terraform apply $ATMOS_COMPONENT -s $ATMOS_STACK
  - name: play
    description: This command plays games
    steps:
      - echo Playing...
    # subcommands
    commands:
      - name: hello
        description: This command says Hello world
        steps:
          - echo Saying Hello world...
          - echo Hello world
      - name: ping
        description: This command plays ping-pong
        steps:
          - echo Playing ping-pong...
          - echo pong

Custom commands support Go templates and ENV vars in commands steps, and Go templates in ENV vars values, as well as allow specifying an external executable to be called to get the value for an ENV var.

They are automatically added to atmos help:

Available Commands:
  aws         Execute 'aws' commands
  completion  Generate the autocompletion script for the specified shell
  describe    Execute 'describe' commands
  helmfile    Execute 'helmfile' commands
  help        Help about any command
  play        This command plays games
  terraform   Execute 'terraform' commands
  tf          Execute terraform commands
  validate    Execute 'validate' commands
  vendor      Execute 'vendor' commands
  version     Print the CLI version
  workflow    Execute a workflow

Custom commands test

atmos play ping
Executing command:
/bin/echo Playing ping-pong...
Playing ping-pong...

Executing command:
/bin/echo pong
pong
atmos play hello
Executing command:
/bin/echo Saying Hello world...
Saying Hello world...

Executing command:
/bin/echo Hello world
Hello world
atmos terraform provision test/test-component-override -s tenant1-ue2-dev
Using ENV vars:
ATMOS_COMPONENT=test/test-component-override
ATMOS_STACK=tenant1-ue2-dev

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

....

Executing command:
/usr/local/bin/atmos terraform apply test/test-component-override -s tenant1-ue2-dev
atmos tf plan test/test-component-override -s tenant1-ue2-dev
# This command gets the value for the ENV var by calling an external executable
Executing command:
/bin/echo ENV_VAR_2_value

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

references

Don't miss a new atmos release

NewReleases is sending notifications on new releases.