Skip to content

Commit 3dc818b

Browse files
authored
Move atmos-gitops-config.yaml to atmos.yaml (#20)
## what * Move `atmos-gitops-config.yaml` to `atmos.yaml`
1 parent 65099c6 commit 3dc818b

File tree

10 files changed

+337
-213
lines changed

10 files changed

+337
-213
lines changed

.github/workflows/test-matrix-2-levels.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
- uses: ./
2525
id: current
2626
with:
27-
atmos-gitops-config-path: "./tests/atmos-gitops.yaml"
27+
atmos-config-path: "./tests"
2828
select-filter: '.settings.github.actions_enabled // false'
2929
nested-matrices-count: '2'
3030

.github/workflows/test-matrix-3-levels.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
- uses: ./
2626
id: current
2727
with:
28-
atmos-gitops-config-path: "./tests/atmos-gitops.yaml"
28+
atmos-config-path: "./tests"
2929
select-filter: '.settings.github.actions_enabled // false'
3030
nested-matrices-count: '3'
3131

.github/workflows/test-positive.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
- uses: ./
2626
id: current
2727
with:
28-
atmos-gitops-config-path: "./tests/atmos-gitops.yaml"
28+
atmos-config-path: "./tests"
2929

3030
outputs:
3131
selected-components: "${{ steps.current.outputs.selected-components }}"

README.md

Lines changed: 174 additions & 88 deletions
Large diffs are not rendered by default.

README.yaml

Lines changed: 120 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -66,27 +66,31 @@ references:
6666
usage: |
6767
### Config
6868
69-
The action expects the atmos gitops configuration file to be present in the repository in `./.github/config/atmos-gitops.yaml`.
69+
The action expects the atmos configuration file `atmos.yaml` to be present in the repository.
7070
The config should have the following structure:
7171
7272
```yaml
73-
atmos-version: 1.45.3
74-
atmos-config-path: ./rootfs/usr/local/etc/atmos/
75-
terraform-state-bucket: cptest-core-ue2-auto-gitops
76-
terraform-state-table: cptest-core-ue2-auto-gitops
77-
terraform-state-role: arn:aws:iam::xxxxxxxxxxxx:role/cptest-core-ue2-auto-gitops-gha
78-
terraform-plan-role: arn:aws:iam::yyyyyyyyyyyy:role/cptest-core-gbl-identity-gitops
79-
terraform-apply-role: arn:aws:iam::yyyyyyyyyyyy:role/cptest-core-gbl-identity-gitops
80-
terraform-version: 1.5.2
81-
aws-region: us-east-2
82-
enable-infracost: false
83-
sort-by: .stack_slug
84-
group-by: .stack_slug | split("-") | [.[0], .[2]] | join("-")
85-
```
86-
73+
integrations:
74+
github:
75+
gitops:
76+
terraform-version: 1.5.2
77+
infracost-enabled: false
78+
artifact-storage:
79+
region: us-east-2
80+
bucket: cptest-core-ue2-auto-gitops
81+
table: cptest-core-ue2-auto-gitops-plan-storage
82+
role: arn:aws:iam::xxxxxxxxxxxx:role/cptest-core-ue2-auto-gitops-gha
83+
role:
84+
plan: arn:aws:iam::yyyyyyyyyyyy:role/cptest-core-gbl-identity-gitops
85+
apply: arn:aws:iam::yyyyyyyyyyyy:role/cptest-core-gbl-identity-gitops
86+
matrix:
87+
sort-by: .stack_slug
88+
group-by: .stack_slug | split("-") | [.[0], .[2]] | join("-")
89+
```
90+
8791
> [!IMPORTANT]
88-
> **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.
89-
92+
> **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.
93+
9094
### GitHub Actions Workflow Example
9195
9296
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: |
101105
steps:
102106
- name: Selected Components
103107
id: components
104-
uses: cloudposse/github-action-atmos-terraform-select-components@v0
108+
uses: cloudposse/github-action-atmos-terraform-select-components@v2
105109
with:
106110
atmos-config-path: "${{ github.workspace }}/rootfs/usr/local/etc/atmos/"
107111
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: |
120124
echo "${{ matrix.stack_slug }}"
121125
```
122126
127+
### Migrating from `v1` to `v2`
128+
129+
The notable changes in `v2` are:
130+
131+
- `v2` works only with `atmos >= 1.63.0`
132+
- `v2` drops `install-terraform` input because terraform is not required for affected stacks call
133+
- `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`.
134+
135+
The following configuration fields now moved to GitHub action inputs with the same names
136+
137+
| name |
138+
|-------------------------|
139+
| `atmos-version` |
140+
| `atmos-config-path` |
141+
142+
143+
The following configuration fields moved to the `atmos.yaml` configuration file.
144+
145+
| name | YAML path in `atmos.yaml` |
146+
|--------------------------|-------------------------------------------------|
147+
| `aws-region` | `integrations.github.gitops.artifact-storage.region` |
148+
| `terraform-state-bucket` | `integrations.github.gitops.artifact-storage.bucket` |
149+
| `terraform-state-table` | `integrations.github.gitops.artifact-storage.table` |
150+
| `terraform-state-role` | `integrations.github.gitops.artifact-storage.role` |
151+
| `terraform-plan-role` | `integrations.github.gitops.role.plan` |
152+
| `terraform-apply-role` | `integrations.github.gitops.role.apply` |
153+
| `terraform-version` | `integrations.github.gitops.terraform-version` |
154+
| `enable-infracost` | `integrations.github.gitops.infracost-enabled` |
155+
| `sort-by` | `integrations.github.gitops.matrix.sort-by` |
156+
| `group-by` | `integrations.github.gitops.matrix.group-by` |
157+
158+
159+
For example, to migrate from `v1` to `v2`, you should have something similar to the following in your `atmos.yaml`:
160+
161+
`./.github/config/atmos.yaml`
162+
```yaml
163+
# ... your existing configuration
164+
165+
integrations:
166+
github:
167+
gitops:
168+
terraform-version: 1.5.2
169+
infracost-enabled: false
170+
artifact-storage:
171+
region: us-east-2
172+
bucket: cptest-core-ue2-auto-gitops
173+
table: cptest-core-ue2-auto-gitops-plan-storage
174+
role: arn:aws:iam::xxxxxxxxxxxx:role/cptest-core-ue2-auto-gitops-gha
175+
role:
176+
plan: arn:aws:iam::yyyyyyyyyyyy:role/cptest-core-gbl-identity-gitops
177+
apply: arn:aws:iam::yyyyyyyyyyyy:role/cptest-core-gbl-identity-gitops
178+
matrix:
179+
sort-by: .stack_slug
180+
group-by: .stack_slug | split("-") | [.[0], .[2]] | join("-")
181+
```
182+
183+
`.github/workflows/main.yaml`
184+
```yaml
185+
- name: Selected Components
186+
id: components
187+
uses: cloudposse/github-action-atmos-terraform-select-components@v2
188+
with:
189+
atmos-config-path: ./rootfs/usr/local/etc/atmos/
190+
jq-query: 'to_entries[] | .key as $parent | .value.components.terraform | to_entries[] | select(.value.settings.github.actions_enabled // false) | [$parent, .key] | join(",")'
191+
```
192+
193+
This corresponds to the `v1` configuration (deprecated) below.
194+
195+
The `v1` configuration file `./.github/config/atmos-gitops.yaml` looked like this:
196+
```yaml
197+
atmos-version: 1.45.3
198+
atmos-config-path: ./rootfs/usr/local/etc/atmos/
199+
terraform-state-bucket: cptest-core-ue2-auto-gitops
200+
terraform-state-table: cptest-core-ue2-auto-gitops
201+
terraform-state-role: arn:aws:iam::xxxxxxxxxxxx:role/cptest-core-ue2-auto-gitops-gha
202+
terraform-plan-role: arn:aws:iam::yyyyyyyyyyyy:role/cptest-core-gbl-identity-gitops
203+
terraform-apply-role: arn:aws:iam::yyyyyyyyyyyy:role/cptest-core-gbl-identity-gitops
204+
terraform-version: 1.5.2
205+
aws-region: us-east-2
206+
enable-infracost: false
207+
sort-by: .stack_slug
208+
group-by: .stack_slug | split("-") | [.[0], .[2]] | join("-")
209+
```
210+
211+
And the `v1` GitHub Action Workflow looked like this.
212+
213+
`.github/workflows/main.yaml`
214+
```yaml
215+
- name: Selected Components
216+
id: components
217+
uses: cloudposse/github-action-atmos-terraform-select-components@v1
218+
with:
219+
atmos-gitops-config-path: ./.github/config/atmos-gitops.yaml
220+
jq-query: 'to_entries[] | .key as $parent | .value.components.terraform | to_entries[] | select(.value.settings.github.actions_enabled // false) | [$parent, .key] | join(",")'
221+
222+
```
223+
224+
123225
### Migrating from `v0` to `v1`
124226
125227
1. `v1` replaces the `jq-query` input parameter with a new parameter called `selected-filter` to simplify the query for end-users.

action.yml

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,13 @@ inputs:
1313
description: The head ref to checkout. If not provided, the head default branch is used.
1414
required: false
1515
default: ${{ github.sha }}
16-
atmos-gitops-config-path:
17-
description: The path to the atmos-gitops.yaml file
16+
atmos-version:
17+
description: The version of atmos to install
1818
required: false
19-
default: ./.github/config/atmos-gitops.yaml
19+
default: ">= 1.63.0"
20+
atmos-config-path:
21+
description: The path to the atmos.yaml file
22+
required: true
2023
jq-version:
2124
description: The version of jq to install if install-jq is true
2225
required: false
@@ -47,40 +50,35 @@ runs:
4750
with:
4851
ref: ${{ inputs.head-ref }}
4952

50-
- name: Read Atmos GitOps config
51-
## We have to reference cloudposse fork of https://github.com/blablacar/action-config-levels
52-
## before https://github.com/blablacar/action-config-levels/pull/16 would be merged
53-
uses: cloudposse/github-action-config-levels@nodejs20
54-
id: config
55-
with:
56-
output_properties: true
57-
patterns: |
58-
- ${{ inputs.atmos-gitops-config-path }}
59-
60-
- name: Install Terraform
61-
uses: hashicorp/setup-terraform@v3
53+
- name: Install JQ
54+
uses: dcarbone/[email protected]
6255
with:
63-
terraform_version: ${{ steps.config.outputs.terraform-version }}
64-
terraform_wrapper: false
56+
version: ${{ inputs.jq-version }}
6557

6658
- name: Install Atmos
6759
uses: cloudposse/github-action-setup-atmos@v2
6860
env:
6961
ATMOS_CLI_CONFIG_PATH: ${{inputs.atmos-config-path}}
7062
with:
71-
atmos-version: ${{ steps.config.outputs.atmos-version }}
63+
atmos-version: ${{ inputs.atmos-version }}
7264
install-wrapper: false
7365

74-
- name: Install JQ
75-
uses: dcarbone/[email protected]
76-
with:
77-
version: ${{ inputs.jq-version }}
66+
- name: Set vars
67+
shell: bash
68+
run: |-
69+
echo "ATMOS_CLI_CONFIG_PATH=$(realpath ${{ inputs.atmos-config-path }})" >> $GITHUB_ENV
70+
71+
- name: config
72+
shell: bash
73+
id: config
74+
run: |-
75+
echo "group-by=$(atmos describe config -f json | jq -r '.integrations.github.gitops.matrix["group-by"]')" >> $GITHUB_OUTPUT
76+
echo "sort-by=$(atmos describe config -f json | jq -r '.integrations.github.gitops.matrix["sort-by"]')" >> $GITHUB_OUTPUT
7877
7978
- name: Filter Components
8079
id: selected-components
8180
shell: bash
8281
env:
83-
ATMOS_CLI_CONFIG_PATH: ${{ steps.config.outputs.atmos-config-path }}
8482
JQUERY: |
8583
with_entries(.value |= (.components.terraform)) | ## Deal with components type of terraform
8684
map_values(map_values(select(${{ inputs.select-filter }}))) | ## Filter components by enabled github actions

atmos.yaml

Lines changed: 0 additions & 69 deletions
This file was deleted.

docs/github-action.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44

55
| Name | Description | Default | Required |
66
|------|-------------|---------|----------|
7-
| atmos-gitops-config-path | The path to the atmos-gitops.yaml file | ./.github/config/atmos-gitops.yaml | false |
7+
| atmos-config-path | The path to the atmos.yaml file | N/A | true |
8+
| atmos-version | The version of atmos to install | >= 1.63.0 | false |
89
| debug | Enable action debug mode. Default: 'false' | false | false |
910
| head-ref | The head ref to checkout. If not provided, the head default branch is used. | ${{ github.sha }} | false |
1011
| jq-version | The version of jq to install if install-jq is true | 1.6 | false |

tests/atmos-gitops.yaml

Lines changed: 0 additions & 11 deletions
This file was deleted.

tests/atmos.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,23 @@ stacks:
5959
# Can also be set using `ATMOS_STACKS_NAME_PATTERN` ENV var
6060
name_pattern: "{tenant}-{environment}-{stage}"
6161

62+
integrations:
63+
github:
64+
gitops:
65+
terraform-version: 1.5.2
66+
infracost-enabled: false
67+
artifact-storage:
68+
region: us-east-2
69+
bucket: cptest-core-ue2-auto-gitops
70+
table: cptest-core-ue2-auto-gitops-plan-storage
71+
role: arn:aws:iam::xxxxxxxxxxxx:role/cptest-core-ue2-auto-gitops-gha
72+
role:
73+
plan: arn:aws:iam::yyyyyyyyyyyy:role/cptest-core-gbl-identity-gitops
74+
apply: arn:aws:iam::yyyyyyyyyyyy:role/cptest-core-gbl-identity-gitops
75+
matrix:
76+
sort-by: .stack_slug
77+
group-by: .stack_slug | split("-") | [.[0], .[2]] | join("-")
78+
6279
workflows:
6380
# Can also be set using `ATMOS_WORKFLOWS_BASE_PATH` ENV var, or `--workflows-dir` command-line arguments
6481
# Supports both absolute and relative paths

0 commit comments

Comments
 (0)