From c4987d283fce7a3fbf48e9e2f160ee1cef87cb3a Mon Sep 17 00:00:00 2001 From: Igor Rodionov Date: Mon, 11 Mar 2024 19:05:53 +0100 Subject: [PATCH] Move `atmos-gitops-config.yaml` to `atmos.yaml` (#63) * Fix readme * Fix readme * Fix readme * Fix readme * Fix readme * Fix readme * Fix readme * Fix readme * Fix readme * Fix readme * Fix readme * Fix readme * Fix readme * Fix readme * Fix readme * Fix readme * Fix readme * Fix readme * Fix readme * Fix readme * Fix readme * Fix readme * Update README * Added rename * Added rename * Added rename * Fix readme * Address comments * Address comments * Replace storage with artifact-storage in atmos.yaml config * Replace storage with artifact-storage in atmos.yaml config * Address comments --- .github/workflows/integration-tests.yml | 23 +- .../workflows/test-changes-exists-drift.yml | 25 +- .github/workflows/test-changes-exists.yml | 24 +- .github/workflows/test-failed-plan-drift.yml | 25 +- .github/workflows/test-failed-plan.yml | 25 +- .github/workflows/test-infra-cost.yml | 26 +- .../workflows/test-no-changes-drift-more.yml | 25 +- .github/workflows/test-no-changes.yml | 25 +- .../test-settings-action-disabled-drift.yml | 25 +- .../test-settings-action-disabled.yml | 25 +- README.md | 267 ++++++++++++------ README.yaml | 140 +++++++-- action.yml | 43 +-- docs/github-action.md | 3 +- tests/atmos.yaml | 17 ++ 15 files changed, 450 insertions(+), 268 deletions(-) diff --git a/.github/workflows/integration-tests.yml b/.github/workflows/integration-tests.yml index 7a1b9bbe6..5520e0a1a 100644 --- a/.github/workflows/integration-tests.yml +++ b/.github/workflows/integration-tests.yml @@ -25,22 +25,19 @@ jobs: - shell: bash run: | mkdir -p ${{ runner.temp }} - cat > ${{ runner.temp }}/atmos-gitops.yaml < ${{ runner.temp }}/atmos-gitops.yaml < ${{ runner.temp }}/atmos-gitops.yaml < ${{ runner.temp }}/atmos-gitops.yaml < ${{ runner.temp }}/atmos-gitops.yaml < ${{ runner.temp }}/atmos-gitops.yaml < ${{ runner.temp }}/atmos-gitops.yaml < ${{ runner.temp }}/atmos-gitops.yaml < ${{ runner.temp }}/atmos-gitops.yaml < ${{ runner.temp }}/atmos-gitops.yaml < -# github-action-atmos-terraform-plan [![Latest Release](https://img.shields.io/github/release/cloudposse/github-action-atmos-terraform-plan.svg)](https://github.com/cloudposse/github-action-atmos-terraform-plan/releases/latest) [![Slack Community](https://slack.cloudposse.com/badge.svg)](https://slack.cloudposse.com) +# github-action-atmos-terraform-plan +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-plan&utm_content=docs - [website]: https://cpco.io/homepage?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/github-action-atmos-terraform-plan&utm_content=website - [github]: https://cpco.io/github?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/github-action-atmos-terraform-plan&utm_content=github - [jobs]: https://cpco.io/jobs?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/github-action-atmos-terraform-plan&utm_content=jobs - [hire]: https://cpco.io/hire?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/github-action-atmos-terraform-plan&utm_content=hire - [slack]: https://cpco.io/slack?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/github-action-atmos-terraform-plan&utm_content=slack - [twitter]: https://cpco.io/twitter?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/github-action-atmos-terraform-plan&utm_content=twitter - [office_hours]: https://cloudposse.com/office-hours?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/github-action-atmos-terraform-plan&utm_content=office_hours - [newsletter]: https://cpco.io/newsletter?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/github-action-atmos-terraform-plan&utm_content=newsletter - [email]: https://cpco.io/email?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/github-action-atmos-terraform-plan&utm_content=email - [commercial_support]: https://cpco.io/commercial-support?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/github-action-atmos-terraform-plan&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-plan&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-plan&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-plan&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-plan&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-plan&utm_content=readme_commercial_support_link - [beacon]: https://ga-beacon.cloudposse.com/UA-76589703-4/cloudposse/github-action-atmos-terraform-plan?pixel&cs=github&cm=readme&an=github-action-atmos-terraform-plan - +Copyright Β© 2017-2024 [Cloud Posse, LLC](https://cpco.io/copyright) + + +README footer + +Beacon diff --git a/README.yaml b/README.yaml index dd8a3ad49..f6cd8cb3d 100644 --- a/README.yaml +++ b/README.yaml @@ -55,26 +55,30 @@ 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. ### Workflow example @@ -102,19 +106,111 @@ usage: |- runs-on: ubuntu-latest steps: - name: Plan Atmos Component - uses: cloudposse/github-action-atmos-terraform-plan@v1 + uses: cloudposse/github-action-atmos-terraform-plan@v2 with: component: "foobar" stack: "plat-ue2-sandbox" - component-path: "components/terraform/s3-bucket" - terraform-plan-role: "arn:aws:iam::111111111111:role/acme-core-gbl-identity-gitops" - terraform-state-bucket: "acme-core-ue2-auto-gitops" - terraform-state-role: "arn:aws:iam::999999999999:role/acme-core-ue2-auto-gitops-gha" - terraform-state-table: "acme-core-ue2-auto-gitops" - aws-region: "us-east-2" + atmos-config-path: ./rootfs/usr/local/etc/atmos/ + atmos-version: 1.63.0 + ``` + + ### 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: Plan Atmos Component + uses: cloudposse/github-action-atmos-terraform-plan@v2 + with: + component: "foobar" + stack: "plat-ue2-sandbox" + atmos-config-path: ./rootfs/usr/local/etc/atmos/ + atmos-version: 1.63.0 + ``` + + 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: Plan Atmos Component + uses: cloudposse/github-action-atmos-terraform-plan@v1 + with: + component: "foobar" + stack: "plat-ue2-sandbox" + atmos-gitops-config-path: ./.github/config/atmos-gitops.yaml + ``` + ### Migrating from `v1` to `v2` 1. `v2` drops the `component-path` variable and instead fetches if directly from the [`atmos.yaml` file](https://atmos.tools/cli/configuration/) automatically. Simply remove the `component-path` argument from your invocations of the `cloudposse/github-action-atmos-terraform-plan` action. diff --git a/action.yml b/action.yml index 20e597e16..1894b9ae5 100644 --- a/action.yml +++ b/action.yml @@ -19,10 +19,13 @@ inputs: description: "Indicate whether this action is used in drift detection workflow." required: true default: 'false' - 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 infracost-api-key: description: "Infracost API key" required: false @@ -59,18 +62,29 @@ runs: - name: Checkout uses: actions/checkout@v4 - - name: config - uses: cloudposse/github-action-config-levels@nodejs20 - id: config + - name: Set atmos cli config path vars + shell: bash + run: |- + echo "ATMOS_CLI_CONFIG_PATH=$(realpath ${{ inputs.atmos-config-path }})" >> $GITHUB_ENV + + - name: Install Atmos + uses: cloudposse/github-action-setup-atmos@v2 with: - output_properties: true - patterns: | - - ${{ inputs.atmos-gitops-config-path }} + atmos-version: ${{ inputs.atmos-version }} + token: ${{ inputs.token }} + install-wrapper: false - - name: Set atmos cli config path vars + - name: config shell: bash + id: config run: |- - echo "ATMOS_CLI_CONFIG_PATH=$(realpath ${{ steps.config.outputs.atmos-config-path }})" >> $GITHUB_ENV + echo "terraform-version=$(atmos describe config -f json | jq -r '.integrations.github.gitops["terraform-version"]')" >> $GITHUB_OUTPUT + echo "enable-infracost=$(atmos describe config -f json | jq -r '.integrations.github.gitops["infracost-enabled"]')" >> $GITHUB_OUTPUT + echo "aws-region=$(atmos describe config -f json | jq -r '.integrations.github.gitops["artifact-storage"].region')" >> $GITHUB_OUTPUT + echo "terraform-state-role=$(atmos describe config -f json | jq -r '.integrations.github.gitops["artifact-storage"].role')" >> $GITHUB_OUTPUT + echo "terraform-state-table=$(atmos describe config -f json | jq -r '.integrations.github.gitops["artifact-storage"].table')" >> $GITHUB_OUTPUT + echo "terraform-state-bucket=$(atmos describe config -f json | jq -r '.integrations.github.gitops["artifact-storage"].bucket')" >> $GITHUB_OUTPUT + echo "terraform-plan-role=$(atmos describe config -f json | jq -r '.integrations.github.gitops.role.plan')" >> $GITHUB_OUTPUT - name: Install Terraform uses: hashicorp/setup-terraform@v3 @@ -78,13 +92,6 @@ runs: terraform_version: ${{ steps.config.outputs.terraform-version }} terraform_wrapper: false - - name: Install Atmos - uses: cloudposse/github-action-setup-atmos@v2 - with: - atmos-version: ${{ steps.config.outputs.atmos-version }} - token: ${{ inputs.token }} - install-wrapper: false - - name: Filter Atmos Settings Value uses: cloudposse/github-action-atmos-get-setting@v1 id: atmos-github-actions-enabled diff --git a/docs/github-action.md b/docs/github-action.md index 77158bc09..26c44b7db 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 | | branding-logo-image | Branding logo image url | https://cloudposse.com/logo-300x69.svg | false | | branding-logo-url | Branding logo url | https://cloudposse.com/ | false | | component | The name of the component to plan. | N/A | true | diff --git a/tests/atmos.yaml b/tests/atmos.yaml index 8ee70cfe6..489143dcf 100644 --- a/tests/atmos.yaml +++ b/tests/atmos.yaml @@ -64,6 +64,23 @@ workflows: # Supports both absolute and relative paths base_path: "stacks/workflows" +integrations: + github: + gitops: + terraform-version: 1.5.2 + infracost-enabled: __INFRACOST_ENABLED__ + artifact-storage: + region: __STORAGE_REGION__ + bucket: __STORAGE_BUCKET__ + table: __STORAGE_TABLE__ + role: __STORAGE_ROLE__ + role: + plan: __PLAN_ROLE__ + apply: __APPLY_ROLE__ + matrix: + sort-by: .stack_slug + group-by: .stack_slug | split("-") | [.[0], .[2]] | join("-") + logs: verbose: false colors: true