github cloudposse/atmos v1.12.0

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

what

  • Update atmos custom commands
  • Update atmos terraform generate backends command

why

  • Update atmos custom commands to allow the command's ENV var values to have access to {{ .ComponentConfig.xxx.yyy.zzz }} Go template variables. If a custom command defines component_config section with component and stack, atmos generates the config for the component in the stack and makes it available in {{ .ComponentConfig.xxx.yyy.zzz }} Go template variables, exposing all the component sections. This is now available in the custom command's steps and ENV vars

Define a custom command:

  - name: show
    description: Execute 'show' commands
    # subcommands
    commands:
      - name: component
        description: Execute 'show component' command
        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 and have access to {{ .ComponentConfig.xxx.yyy.zzz }} Go template variables
        env:
          - key: ATMOS_COMPONENT
            value: "{{ .Arguments.component }}"
          - key: ATMOS_STACK
            value: "{{ .Flags.stack }}"
          - key: ATMOS_TENANT
            value: "{{ .ComponentConfig.vars.tenant }}"
          - key: ATMOS_STAGE
            value: "{{ .ComponentConfig.vars.stage }}"
          - key: ATMOS_ENVIRONMENT
            value: "{{ .ComponentConfig.vars.environment }}"
          - key: ATMOS_IS_PROD
            value: "{{ .ComponentConfig.settings.config.is_prod }}"
        # If a custom command defines 'component_config' section with 'component' and 'stack', 'atmos' generates the config for the component in the stack
        # and makes it available in {{ .ComponentConfig.xxx.yyy.zzz }} Go template variables,
        # exposing all the component sections (which are also shown by 'atmos describe component' command)
        component_config:
          component: "{{ .Arguments.component }}"
          stack: "{{ .Flags.stack }}"
        # steps support Go templates and have access to {{ .ComponentConfig.xxx.yyy.zzz }} Go template variables
        steps:
          - 'echo Atmos component: {{ .Arguments.component }}'
          - 'echo Atmos stack: {{ .Flags.stack }}'
          - 'echo Terraform component: {{ .ComponentConfig.component }}'
          - 'echo Backend S3 bucket: {{ .ComponentConfig.backend.bucket }}'
          - 'echo Terraform workspace: {{ .ComponentConfig.workspace }}'
          - 'echo Namespace: {{ .ComponentConfig.vars.namespace }}'
          - 'echo Tenant: {{ .ComponentConfig.vars.tenant }}'
          - 'echo Environment: {{ .ComponentConfig.vars.environment }}'
          - 'echo Stage: {{ .ComponentConfig.vars.stage }}'
          - 'echo settings.spacelift.workspace_enabled: {{ .ComponentConfig.settings.spacelift.workspace_enabled }}'
          - 'echo Dependencies: {{ .ComponentConfig.deps }}'
          - 'echo settings.config.is_prod: {{ .ComponentConfig.settings.config.is_prod }}'

Then run atmos show component infra/vpc -s tenant1-ue2-prod - you'll see the ENV var values populated from {{ .ComponentConfig.xxx.yyy.zzz }} template variables:

Using ENV vars:
ATMOS_COMPONENT=infra/vpc
ATMOS_STACK=tenant1-ue2-prod
ATMOS_TENANT=tenant1
ATMOS_STAGE=prod
ATMOS_ENVIRONMENT=ue2
ATMOS_IS_PROD=true
  • Update atmos terraform generate backends command to allow generating backend config files per stack (tenant/environment/stage/component) and write the files into a separate folder (with subfolders). This is useful when using atmos with atlantis and when components use different terraform state S3 buckets per stack (tenant, environment, stage, account). In atlantis project config template you then can use -backend-config=backends/$PROJECT_NAME-backend.tf

Supported flags:

  • --file-template - backend template (the file path, file name, and file extension)
  • --stacks - only process the specified stacks (comma-separated values)
  • --components - only process the specified components (comma-separated values)
  • --format - supported formats: hcl, json (hcl is default)

If --file-template flag is not provided, the command will write the backends to the terraform components folders - this is the default behavior and is used when all components in all stacks use the same TF backend.

atmos terraform generate backends

Writing backend config for the component 'infra/vpc' to file 'examples/complete/components/terraform/infra/vpc/backend.tf'
Writing backend config for the component 'test/test-component' to file 'examples/complete/components/terraform/test/test-component/backend.tf'
Writing backend config for the component 'top-level-component1' to file 'examples/complete/components/terraform/top-level-component1/backend.tf'

If --file-template flag is specified, then the backend config files are generated per stack/component and can be written into any folder (with subfolders)

atmos terraform generate backends --file-template backends/{tenant}-{environment}-{stage}-{component}.tf --components infra/vpc --stacks tenant1-ue2-dev,tenant2-ue2-dev

Writing backend config for the component 'infra/vpc' to file 'backends/tenant1-ue2-dev-infra-vpc.tf'
Writing backend config for the component 'infra/vpc' to file 'backends/tenant2-ue2-dev-infra-vpc.tf'
atmos terraform generate backends --file-template backends/{tenant}-{environment}-{stage}-{component}.tf --components infra/vpc,test/test-component --stacks tenant1-ue2-dev,tenant2-ue2-dev

Writing backend config for the component 'test/test-component' to file 'backends/tenant2-ue2-dev-test-test-component.tf'
Writing backend config for the component 'infra/vpc' to file 'backends/tenant2-ue2-dev-infra-vpc.tf'
Writing backend config for the component 'test/test-component' to file 'backends/tenant1-ue2-dev-test-test-component.tf'
Writing backend config for the component 'infra/vpc' to file 'backends/tenant1-ue2-dev-infra-vpc.tf'
atmos terraform generate backends --file-template backends/{tenant}/{environment}/{stage}/{component}.tf.json --components infra/vpc,test/test-component --stacks tenant1-ue2-dev,tenant2-ue2-dev --format json

Writing backend config for the component 'test/test-component' to file 'backends/tenant2/ue2/dev/test-test-component.tf.json'
Writing backend config for the component 'infra/vpc' to file 'backends/tenant2/ue2/dev/infra-vpc.tf.json'
Writing backend config for the component 'test/test-component' to file 'backends/tenant1/ue2/dev/test-test-component.tf.json'
Writing backend config for the component 'infra/vpc' to file 'backends/tenant1/ue2/dev/infra-vpc.tf.json'

image


image


Don't miss a new atmos release

NewReleases is sending notifications on new releases.