Skip to main content

GitHub Action: atmos-terraform-select-components

GitHub Action that outputs list of Atmos components by jq query

Introduction

GitHub Action that outputs list of Atmos components by jq query.

For example following query will fetch components that have in settings set github.actions_enabled: true:

to_entries[] | .key as $parent | .value.components.terraform | to_entries[] | select(.value.settings.github.actions_enabled // false) | [$parent, .key] | join(",")

Output of this action is a list of basic component information. For example:

[
{
"stack": "plat-ue2-sandbox",
"component": "test-component-01",
"stack_slug": "plat-ue2-sandbox-test-component-01",
"component_path": "components/terraform/s3-bucket"
}
]

Usage

GitHub Actions Workflow Example

In following GitHub workflow example first job will filter components that have settings github.actions_enabled: true and then in following job stack_slug will be printed to stdout.

  jobs:
selected-components:
runs-on: ubuntu-latest
name: github-action-atmos-terraform-select-components
outputs:
matrix: ${{ steps.components.outputs.matrix }}
steps:
- name: github-action-atmos-terraform-select-components
id: components
uses: cloudposse/github-action-atmos-terraform-select-components@v0
with:
atmos-config-path: "${{ github.workspace }}/rootfs/usr/local/etc/atmos/"
jq-query: 'to_entries[] | .key as $parent | .value.components.terraform | to_entries[] | select(.value.settings.github.actions_enabled // false) | [$parent, .key] | join(",")'

print-stack-slug:
runs-on: ubuntu-latest
needs:
- selected-components
if: ${{ needs.selected-components.outputs.matrix != '{"include":[]}' }}
strategy:
matrix: ${{ fromJson(needs.selected-components.outputs.matrix) }}
name: github-action-atmos-terraform-select-components
steps:
- name: github-action-atmos-terraform-select-components
run:
echo "${{ matrix.stack_slug }}"