diff --git a/.github/workflows/test-matrix-2-levels.yml b/.github/workflows/test-matrix-2-levels.yml index d15169d..7cf4dac 100644 --- a/.github/workflows/test-matrix-2-levels.yml +++ b/.github/workflows/test-matrix-2-levels.yml @@ -24,7 +24,7 @@ jobs: - uses: ./ id: current with: - atmos-gitops-config-path: "./tests/atmos-gitops.yaml" + atmos-config-path: "./tests" select-filter: '.settings.github.actions_enabled // false' nested-matrices-count: '2' diff --git a/.github/workflows/test-matrix-3-levels.yml b/.github/workflows/test-matrix-3-levels.yml index 840344f..107324e 100644 --- a/.github/workflows/test-matrix-3-levels.yml +++ b/.github/workflows/test-matrix-3-levels.yml @@ -25,7 +25,7 @@ jobs: - uses: ./ id: current with: - atmos-gitops-config-path: "./tests/atmos-gitops.yaml" + atmos-config-path: "./tests" select-filter: '.settings.github.actions_enabled // false' nested-matrices-count: '3' diff --git a/.github/workflows/test-positive.yml b/.github/workflows/test-positive.yml index e8d3a0f..54256db 100644 --- a/.github/workflows/test-positive.yml +++ b/.github/workflows/test-positive.yml @@ -25,7 +25,7 @@ jobs: - uses: ./ id: current with: - atmos-gitops-config-path: "./tests/atmos-gitops.yaml" + atmos-config-path: "./tests" outputs: selected-components: "${{ steps.current.outputs.selected-components }}" diff --git a/README.md b/README.md index e3a8bf1..526e47e 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,8 @@ - -# github-action-atmos-terraform-select-components - - [![Latest Release](https://img.shields.io/github/release/cloudposse/github-action-atmos-terraform-select-components.svg)](https://github.com/cloudposse/github-action-atmos-terraform-select-components/releases/latest) [![Slack Community](https://slack.cloudposse.com/badge.svg)](https://slack.cloudposse.com) +# github-action-atmos-terraform-select-components +Latest ReleaseSlack Community -[![README Header][readme_header_img]][readme_header_link] - -[![Cloud Posse][logo]](https://cpco.io/homepage) - - [logo]: https://cloudposse.com/logo-300x69.svg - [docs]: https://cpco.io/docs?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/github-action-atmos-terraform-select-components&utm_content=docs - [website]: https://cpco.io/homepage?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/github-action-atmos-terraform-select-components&utm_content=website - [github]: https://cpco.io/github?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/github-action-atmos-terraform-select-components&utm_content=github - [jobs]: https://cpco.io/jobs?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/github-action-atmos-terraform-select-components&utm_content=jobs - [hire]: https://cpco.io/hire?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/github-action-atmos-terraform-select-components&utm_content=hire - [slack]: https://cpco.io/slack?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/github-action-atmos-terraform-select-components&utm_content=slack - [twitter]: https://cpco.io/twitter?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/github-action-atmos-terraform-select-components&utm_content=twitter - [office_hours]: https://cloudposse.com/office-hours?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/github-action-atmos-terraform-select-components&utm_content=office_hours - [newsletter]: https://cpco.io/newsletter?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/github-action-atmos-terraform-select-components&utm_content=newsletter - [email]: https://cpco.io/email?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/github-action-atmos-terraform-select-components&utm_content=email - [commercial_support]: https://cpco.io/commercial-support?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/github-action-atmos-terraform-select-components&utm_content=commercial_support - [we_love_open_source]: https://cpco.io/we-love-open-source?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/github-action-atmos-terraform-select-components&utm_content=we_love_open_source - [terraform_modules]: https://cpco.io/terraform-modules?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/github-action-atmos-terraform-select-components&utm_content=terraform_modules - [readme_header_img]: https://cloudposse.com/readme/header/img - [readme_header_link]: https://cloudposse.com/readme/header/link?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/github-action-atmos-terraform-select-components&utm_content=readme_header_link - [readme_footer_img]: https://cloudposse.com/readme/footer/img - [readme_footer_link]: https://cloudposse.com/readme/footer/link?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/github-action-atmos-terraform-select-components&utm_content=readme_footer_link - [readme_commercial_support_img]: https://cloudposse.com/readme/commercial-support/img - [readme_commercial_support_link]: https://cloudposse.com/readme/commercial-support/link?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/github-action-atmos-terraform-select-components&utm_content=readme_commercial_support_link - [beacon]: https://ga-beacon.cloudposse.com/UA-76589703-4/cloudposse/github-action-atmos-terraform-select-components?pixel&cs=github&cm=readme&an=github-action-atmos-terraform-select-components - +Copyright Β© 2017-2024 [Cloud Posse, LLC](https://cpco.io/copyright) + + +README footer + +Beacon diff --git a/README.yaml b/README.yaml index d3f7c78..88ea59e 100644 --- a/README.yaml +++ b/README.yaml @@ -66,27 +66,31 @@ references: usage: | ### Config - The action expects the atmos gitops configuration file to be present in the repository in `./.github/config/atmos-gitops.yaml`. + The action expects the atmos configuration file `atmos.yaml` to be present in the repository. The config should have the following structure: ```yaml - atmos-version: 1.45.3 - atmos-config-path: ./rootfs/usr/local/etc/atmos/ - terraform-state-bucket: cptest-core-ue2-auto-gitops - terraform-state-table: cptest-core-ue2-auto-gitops - terraform-state-role: arn:aws:iam::xxxxxxxxxxxx:role/cptest-core-ue2-auto-gitops-gha - terraform-plan-role: arn:aws:iam::yyyyyyyyyyyy:role/cptest-core-gbl-identity-gitops - terraform-apply-role: arn:aws:iam::yyyyyyyyyyyy:role/cptest-core-gbl-identity-gitops - terraform-version: 1.5.2 - aws-region: us-east-2 - enable-infracost: false - sort-by: .stack_slug - group-by: .stack_slug | split("-") | [.[0], .[2]] | join("-") - ``` - + integrations: + github: + gitops: + terraform-version: 1.5.2 + infracost-enabled: false + artifact-storage: + region: us-east-2 + bucket: cptest-core-ue2-auto-gitops + table: cptest-core-ue2-auto-gitops-plan-storage + role: arn:aws:iam::xxxxxxxxxxxx:role/cptest-core-ue2-auto-gitops-gha + role: + plan: arn:aws:iam::yyyyyyyyyyyy:role/cptest-core-gbl-identity-gitops + apply: arn:aws:iam::yyyyyyyyyyyy:role/cptest-core-gbl-identity-gitops + matrix: + sort-by: .stack_slug + group-by: .stack_slug | split("-") | [.[0], .[2]] | join("-") + ``` + > [!IMPORTANT] - > **Please note!** the `terraform-state-*` parameters refer to the S3 Bucket and corresponding meta storage DynamoDB table used to store the Terraform Plan files, and not the "Terraform State". These parameters will be renamed in a subsequent release. - + > **Please note!** This GitHub Action only works with `atmos >= 1.63.0`. If you are using `atmos < 1.63.0` please use `v1` version of this action. + ### 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. @@ -101,7 +105,7 @@ usage: | steps: - name: Selected Components id: components - uses: cloudposse/github-action-atmos-terraform-select-components@v0 + uses: cloudposse/github-action-atmos-terraform-select-components@v2 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(",")' @@ -120,6 +124,104 @@ usage: | echo "${{ matrix.stack_slug }}" ``` + ### Migrating from `v1` to `v2` + + The notable changes in `v2` are: + + - `v2` works only with `atmos >= 1.63.0` + - `v2` drops `install-terraform` input because terraform is not required for affected stacks call + - `v2` drops `atmos-gitops-config-path` input and the `./.github/config/atmos-gitops.yaml` config file. Now you have to use GitHub Actions environment variables to specify the location of the `atmos.yaml`. + + The following configuration fields now moved to GitHub action inputs with the same names + + | name | + |-------------------------| + | `atmos-version` | + | `atmos-config-path` | + + + The following configuration fields moved to the `atmos.yaml` configuration file. + + | name | YAML path in `atmos.yaml` | + |--------------------------|-------------------------------------------------| + | `aws-region` | `integrations.github.gitops.artifact-storage.region` | + | `terraform-state-bucket` | `integrations.github.gitops.artifact-storage.bucket` | + | `terraform-state-table` | `integrations.github.gitops.artifact-storage.table` | + | `terraform-state-role` | `integrations.github.gitops.artifact-storage.role` | + | `terraform-plan-role` | `integrations.github.gitops.role.plan` | + | `terraform-apply-role` | `integrations.github.gitops.role.apply` | + | `terraform-version` | `integrations.github.gitops.terraform-version` | + | `enable-infracost` | `integrations.github.gitops.infracost-enabled` | + | `sort-by` | `integrations.github.gitops.matrix.sort-by` | + | `group-by` | `integrations.github.gitops.matrix.group-by` | + + + For example, to migrate from `v1` to `v2`, you should have something similar to the following in your `atmos.yaml`: + + `./.github/config/atmos.yaml` + ```yaml + # ... your existing configuration + + integrations: + github: + gitops: + terraform-version: 1.5.2 + infracost-enabled: false + artifact-storage: + region: us-east-2 + bucket: cptest-core-ue2-auto-gitops + table: cptest-core-ue2-auto-gitops-plan-storage + role: arn:aws:iam::xxxxxxxxxxxx:role/cptest-core-ue2-auto-gitops-gha + role: + plan: arn:aws:iam::yyyyyyyyyyyy:role/cptest-core-gbl-identity-gitops + apply: arn:aws:iam::yyyyyyyyyyyy:role/cptest-core-gbl-identity-gitops + matrix: + sort-by: .stack_slug + group-by: .stack_slug | split("-") | [.[0], .[2]] | join("-") + ``` + + `.github/workflows/main.yaml` + ```yaml + - name: Selected Components + id: components + uses: cloudposse/github-action-atmos-terraform-select-components@v2 + with: + atmos-config-path: ./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(",")' + ``` + + This corresponds to the `v1` configuration (deprecated) below. + + The `v1` configuration file `./.github/config/atmos-gitops.yaml` looked like this: + ```yaml + atmos-version: 1.45.3 + atmos-config-path: ./rootfs/usr/local/etc/atmos/ + terraform-state-bucket: cptest-core-ue2-auto-gitops + terraform-state-table: cptest-core-ue2-auto-gitops + terraform-state-role: arn:aws:iam::xxxxxxxxxxxx:role/cptest-core-ue2-auto-gitops-gha + terraform-plan-role: arn:aws:iam::yyyyyyyyyyyy:role/cptest-core-gbl-identity-gitops + terraform-apply-role: arn:aws:iam::yyyyyyyyyyyy:role/cptest-core-gbl-identity-gitops + terraform-version: 1.5.2 + aws-region: us-east-2 + enable-infracost: false + sort-by: .stack_slug + group-by: .stack_slug | split("-") | [.[0], .[2]] | join("-") + ``` + + And the `v1` GitHub Action Workflow looked like this. + + `.github/workflows/main.yaml` + ```yaml + - name: Selected Components + id: components + uses: cloudposse/github-action-atmos-terraform-select-components@v1 + with: + atmos-gitops-config-path: ./.github/config/atmos-gitops.yaml + jq-query: 'to_entries[] | .key as $parent | .value.components.terraform | to_entries[] | select(.value.settings.github.actions_enabled // false) | [$parent, .key] | join(",")' + + ``` + + ### Migrating from `v0` to `v1` 1. `v1` replaces the `jq-query` input parameter with a new parameter called `selected-filter` to simplify the query for end-users. diff --git a/action.yml b/action.yml index bcd1f3c..17c2fa4 100644 --- a/action.yml +++ b/action.yml @@ -13,10 +13,13 @@ inputs: description: The head ref to checkout. If not provided, the head default branch is used. required: false default: ${{ github.sha }} - atmos-gitops-config-path: - description: The path to the atmos-gitops.yaml file + atmos-version: + description: The version of atmos to install required: false - default: ./.github/config/atmos-gitops.yaml + default: ">= 1.63.0" + atmos-config-path: + description: The path to the atmos.yaml file + required: true jq-version: description: The version of jq to install if install-jq is true required: false @@ -47,40 +50,35 @@ runs: with: ref: ${{ inputs.head-ref }} - - name: Read Atmos GitOps config - ## We have to reference cloudposse fork of https://github.com/blablacar/action-config-levels - ## before https://github.com/blablacar/action-config-levels/pull/16 would be merged - uses: cloudposse/github-action-config-levels@nodejs20 - id: config - with: - output_properties: true - patterns: | - - ${{ inputs.atmos-gitops-config-path }} - - - name: Install Terraform - uses: hashicorp/setup-terraform@v3 + - name: Install JQ + uses: dcarbone/install-jq-action@v1.0.1 with: - terraform_version: ${{ steps.config.outputs.terraform-version }} - terraform_wrapper: false + version: ${{ inputs.jq-version }} - name: Install Atmos uses: cloudposse/github-action-setup-atmos@v2 env: ATMOS_CLI_CONFIG_PATH: ${{inputs.atmos-config-path}} with: - atmos-version: ${{ steps.config.outputs.atmos-version }} + atmos-version: ${{ inputs.atmos-version }} install-wrapper: false - - name: Install JQ - uses: dcarbone/install-jq-action@v2.1.0 - with: - version: ${{ inputs.jq-version }} + - name: Set vars + shell: bash + run: |- + echo "ATMOS_CLI_CONFIG_PATH=$(realpath ${{ inputs.atmos-config-path }})" >> $GITHUB_ENV + + - name: config + shell: bash + id: config + run: |- + echo "group-by=$(atmos describe config -f json | jq -r '.integrations.github.gitops.matrix["group-by"]')" >> $GITHUB_OUTPUT + echo "sort-by=$(atmos describe config -f json | jq -r '.integrations.github.gitops.matrix["sort-by"]')" >> $GITHUB_OUTPUT - name: Filter Components id: selected-components shell: bash env: - ATMOS_CLI_CONFIG_PATH: ${{ steps.config.outputs.atmos-config-path }} JQUERY: | with_entries(.value |= (.components.terraform)) | ## Deal with components type of terraform map_values(map_values(select(${{ inputs.select-filter }}))) | ## Filter components by enabled github actions diff --git a/atmos.yaml b/atmos.yaml deleted file mode 100644 index d8fa3e7..0000000 --- a/atmos.yaml +++ /dev/null @@ -1,69 +0,0 @@ -# CLI config is loaded from the following locations (from lowest to highest priority): -# system dir (`/usr/local/etc/atmos` on Linux, `%LOCALAPPDATA%/atmos` on Windows) -# home dir (~/.atmos) -# current directory -# ENV vars -# Command-line arguments -# -# It supports POSIX-style Globs for file names/paths (double-star `**` is supported) -# https://en.wikipedia.org/wiki/Glob_(programming) - -# Base path for components, stacks and workflows configurations. -# Can also be set using `ATMOS_BASE_PATH` ENV var, or `--base-path` command-line argument. -# Supports both absolute and relative paths. -# If not provided or is an empty string, `components.terraform.base_path`, `components.helmfile.base_path`, `stacks.base_path` and `workflows.base_path` -# are independent settings (supporting both absolute and relative paths). -# If `base_path` is provided, `components.terraform.base_path`, `components.helmfile.base_path`, `stacks.base_path` and `workflows.base_path` -# are considered paths relative to `base_path`. -base_path: "" - -components: - terraform: - # Can also be set using `ATMOS_COMPONENTS_TERRAFORM_BASE_PATH` ENV var, or `--terraform-dir` command-line argument - # Supports both absolute and relative paths - base_path: "components/terraform" - # Can also be set using `ATMOS_COMPONENTS_TERRAFORM_APPLY_AUTO_APPROVE` ENV var - apply_auto_approve: false - # Can also be set using `ATMOS_COMPONENTS_TERRAFORM_DEPLOY_RUN_INIT` ENV var, or `--deploy-run-init` command-line argument - deploy_run_init: true - # Can also be set using `ATMOS_COMPONENTS_TERRAFORM_INIT_RUN_RECONFIGURE` ENV var, or `--init-run-reconfigure` command-line argument - init_run_reconfigure: true - # Can also be set using `ATMOS_COMPONENTS_TERRAFORM_AUTO_GENERATE_BACKEND_FILE` ENV var, or `--auto-generate-backend-file` command-line argument - auto_generate_backend_file: true - helmfile: - # Can also be set using `ATMOS_COMPONENTS_HELMFILE_BASE_PATH` ENV var, or `--helmfile-dir` command-line argument - # Supports both absolute and relative paths - base_path: "components/helmfile" - # Can also be set using `ATMOS_COMPONENTS_HELMFILE_KUBECONFIG_PATH` ENV var - kubeconfig_path: "/conf/.kube/" - # Can also be set using `ATMOS_COMPONENTS_HELMFILE_HELM_AWS_PROFILE_PATTERN` ENV var - helm_aws_profile_pattern: "{namespace}-{tenant}-gbl-{stage}-helm" - # Can also be set using `ATMOS_COMPONENTS_HELMFILE_CLUSTER_NAME_PATTERN` ENV var - cluster_name_pattern: "{namespace}-{tenant}-{environment}-{stage}-eks-cluster" - -stacks: - # Can also be set using `ATMOS_STACKS_BASE_PATH` ENV var, or `--config-dir` and `--stacks-dir` command-line arguments - # Supports both absolute and relative paths - base_path: "stacks" - # Can also be set using `ATMOS_STACKS_INCLUDED_PATHS` ENV var (comma-separated values string) - # Since we are distinguishing stacks based on namespace, and namespace is not part - # of the stack name, we have to set `included_paths` via the ENV var in the Dockerfile - included_paths: - - "orgs/**/*" - # Can also be set using `ATMOS_STACKS_EXCLUDED_PATHS` ENV var (comma-separated values string) - excluded_paths: - - "**/_defaults.yaml" - # exclude workflows directory if otherwise included in `included_paths` above - # - "workflows/**/*" - - # Can also be set using `ATMOS_STACKS_NAME_PATTERN` ENV var - name_pattern: "{tenant}-{environment}-{stage}" - -workflows: - # Can also be set using `ATMOS_WORKFLOWS_BASE_PATH` ENV var, or `--workflows-dir` command-line arguments - # Supports both absolute and relative paths - base_path: "stacks/workflows" - -logs: - verbose: false - colors: true diff --git a/docs/github-action.md b/docs/github-action.md index 78f65a0..e8ccfff 100644 --- a/docs/github-action.md +++ b/docs/github-action.md @@ -4,7 +4,8 @@ | Name | Description | Default | Required | |------|-------------|---------|----------| -| atmos-gitops-config-path | The path to the atmos-gitops.yaml file | ./.github/config/atmos-gitops.yaml | false | +| atmos-config-path | The path to the atmos.yaml file | N/A | true | +| atmos-version | The version of atmos to install | >= 1.63.0 | false | | debug | Enable action debug mode. Default: 'false' | false | false | | head-ref | The head ref to checkout. If not provided, the head default branch is used. | ${{ github.sha }} | false | | jq-version | The version of jq to install if install-jq is true | 1.6 | false | diff --git a/tests/atmos-gitops.yaml b/tests/atmos-gitops.yaml deleted file mode 100644 index db46a85..0000000 --- a/tests/atmos-gitops.yaml +++ /dev/null @@ -1,11 +0,0 @@ -atmos-version: 1.45.3 -atmos-config-path: ./tests/ -terraform-state-bucket: cptest-core-ue2-auto-gitops -terraform-state-table: cptest-core-ue2-auto-gitops -terraform-state-role: arn:aws:iam::xxxxxxxxxxxx:role/cptest-core-ue2-auto-gitops-gha -terraform-plan-role: arn:aws:iam::yyyyyyyyyyyy:role/cptest-core-gbl-identity-gitops -terraform-apply-role: arn:aws:iam::yyyyyyyyyyyy:role/cptest-core-gbl-identity-gitops -terraform-version: 1.5.2 -aws-region: us-east-2 -sort-by: .stack_slug -group-by: .stack_slug | split("-") | [.[0], .[2]] | join("-") diff --git a/tests/atmos.yaml b/tests/atmos.yaml index 8ee70cf..860c3f1 100644 --- a/tests/atmos.yaml +++ b/tests/atmos.yaml @@ -59,6 +59,23 @@ stacks: # Can also be set using `ATMOS_STACKS_NAME_PATTERN` ENV var name_pattern: "{tenant}-{environment}-{stage}" +integrations: + github: + gitops: + terraform-version: 1.5.2 + infracost-enabled: false + artifact-storage: + region: us-east-2 + bucket: cptest-core-ue2-auto-gitops + table: cptest-core-ue2-auto-gitops-plan-storage + role: arn:aws:iam::xxxxxxxxxxxx:role/cptest-core-ue2-auto-gitops-gha + role: + plan: arn:aws:iam::yyyyyyyyyyyy:role/cptest-core-gbl-identity-gitops + apply: arn:aws:iam::yyyyyyyyyyyy:role/cptest-core-gbl-identity-gitops + matrix: + sort-by: .stack_slug + group-by: .stack_slug | split("-") | [.[0], .[2]] | join("-") + workflows: # Can also be set using `ATMOS_WORKFLOWS_BASE_PATH` ENV var, or `--workflows-dir` command-line arguments # Supports both absolute and relative paths