Skip to content

Commit

Permalink
Move atmos-gitops-config.yaml to atmos.yaml (#20)
Browse files Browse the repository at this point in the history
## what
* Move `atmos-gitops-config.yaml` to `atmos.yaml`
  • Loading branch information
goruha authored Mar 11, 2024
1 parent 65099c6 commit 3dc818b
Show file tree
Hide file tree
Showing 10 changed files with 337 additions and 213 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test-matrix-2-levels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-matrix-3-levels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-positive.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}"
Expand Down
262 changes: 174 additions & 88 deletions README.md

Large diffs are not rendered by default.

138 changes: 120 additions & 18 deletions README.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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(",")'
Expand All @@ -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.
Expand Down
44 changes: 21 additions & 23 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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/[email protected]
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/[email protected]
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
Expand Down
69 changes: 0 additions & 69 deletions atmos.yaml

This file was deleted.

3 changes: 2 additions & 1 deletion docs/github-action.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
11 changes: 0 additions & 11 deletions tests/atmos-gitops.yaml

This file was deleted.

17 changes: 17 additions & 0 deletions tests/atmos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3dc818b

Please sign in to comment.