generated from cloudposse-github-actions/composite-template
-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathREADME.yaml
394 lines (311 loc) · 13.4 KB
/
README.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
---
#
# This is the canonical configuration for the `README.md`
# Run `make readme` to rebuild the `README.md`
#
# Name of this project
name: github-action-atmos-affected
# Tags of this project
tags:
- github-action
# Logo for this project
#logo: docs/logo.png
# License of this project
license: "APACHE2"
# Canonical GitHub repo
github_repo: cloudposse/github-action-atmos-affected-stacks
# Badges to display
badges:
- name: "Latest Release"
image: "https://img.shields.io/github/release/cloudposse/github-action-atmos-affected-stacks.svg"
url: "https://github.com/cloudposse/github-action-atmos-affected-stacks/releases/latest"
- name: "Slack Community"
image: "https://slack.cloudposse.com/badge.svg"
url: "https://slack.cloudposse.com"
related: []
# Short description of this project
description: A GitHub Action to get a list of affected atmos stacks for a pull request
introduction: |-
This is a GitHub Action to get a list of affected atmos stacks for a pull request. It optionally installs
`atmos` and `jq` and runs `atmos describe affected` to get the list of affected stacks. It provides the
raw list of affected stacks as an output as well as a matrix that can be used further in GitHub action jobs.
references: []
# How to use this project
usage: |-
### Config
> [!IMPORTANT]
> **Please note!** This GitHub Action only works with `atmos >= 1.99.0`.
> If you are using `atmos >= 1.80.0, < 1.99.0` please use `v5` version of this action.
> If you are using `atmos >= 1.63.0, < 1.80.0` please use `v3` or `v4` version of this action.
> If you are using `atmos < 1.63.0` please use `v2` version of this action.
The action expects the atmos configuration file `atmos.yaml` to be present in the repository.
The action supports AWS and Azure to store Terraform plan files.
You can read more about plan storage in the [cloudposse/github-action-terraform-plan-storage](https://github.com/cloudposse/github-action-terraform-plan-storage?tab=readme-ov-file#aws-default) documentation.
Depends of cloud provider the following fields should be set in the `atmos.yaml`:
#### AWS
The config should have the following structure:
```yaml
integrations:
github:
gitops:
opentofu-version: 1.7.3
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
# Set `apply` empty if you don't want to assume IAM role before terraform apply
apply: arn:aws:iam::yyyyyyyyyyyy:role/cptest-core-gbl-identity-gitops
matrix:
sort-by: .stack_slug
group-by: .stack_slug | split("-") | [.[0], .[2]] | join("-")
```
#### Azure
The config should have the following structure:
```yaml
integrations:
github:
gitops:
opentofu-version: 1.7.3
terraform-version: 1.5.2
infracost-enabled: false
artifact-storage:
plan-repository-type: azureblob
blob-account-name: tfplans
blob-container-name: plans
metadata-repository-type: cosmos
cosmos-container-name: terraform-plan-storage
cosmos-database-name: terraform-plan-storage
cosmos-endpoint: "https://my-cosmo-account.documents.azure.com:443/"
# We remove the `role` section as it is AWS specific
matrix:
sort-by: .stack_slug
group-by: .stack_slug | split("-") | [.[0], .[2]] | join("-")
```
### Stack level configuration
> [!IMPORTANT]
> Wherever it is possible to specify `integration.github.gitops` on stack level
> it is required to define default values in `atmos.yaml`
It is possible to override integration settings on a stack level by defining `settings.integrations`.
```yaml
components:
terraform:
foobar:
settings:
integrations:
github:
gitops:
artifact-storage:
bucket: cptest-plat-ue2-auto-gitops
table: cptest-plat-ue2-auto-gitops-plan-storage
role: arn:aws:iam::xxxxxxxxxxxx:role/cptest-plat-ue2-auto-gitops-gha
role:
# Set `plan` empty if you don't want to assume IAM role before terraform plan
plan: arn:aws:iam::yyyyyyyyyyyy:role/cptest-plat-gbl-identity-gitops
apply: arn:aws:iam::yyyyyyyyyyyy:role/cptest-plat-gbl-identity-gitops
```
### Support OpenTofu
This action supports [OpenTofu](https://opentofu.org/).
> [!IMPORTANT]
> **Please note!** OpenTofu supported by Atmos `>= 1.73.0`.
> For details [read](https://atmos.tools/core-concepts/projects/configuration/opentofu/)
To enable OpenTofu add the following settings to `atmos.yaml`
* Set the `opentofu-version` in the `atmos.yaml` to the desired version
* Set `components.terraform.command` to `tofu`
#### Example
```yaml
components:
terraform:
command: tofu
...
integrations:
github:
gitops:
opentofu-version: 1.7.3
...
```
### Workflow example
```yaml
name: Pull Request
on:
pull_request:
branches: [ 'main' ]
types: [opened, synchronize, reopened, closed, labeled, unlabeled]
jobs:
atmos-affected:
runs-on: ubuntu-latest
steps:
- id: affected
uses: cloudposse/github-action-atmos-affected-stacks@v6
with:
atmos-config-path: ./rootfs/usr/local/etc/atmos/
atmos-version: 1.99.0
nested-matrices-count: 1
outputs:
matrix: ${{ steps.affected.outputs.matrix }}
has-affected-stacks: ${{ steps.affected.outputs.has-affected-stacks }}
# This job is an example how to use the affected stacks with the matrix strategy
atmos-plan:
needs: ["atmos-affected"]
if: ${{ needs.atmos-affected.outputs.has-affected-stacks == 'true' }}
name: Plan ${{ matrix.stack_slug }}
runs-on: ubuntu-latest
strategy:
max-parallel: 10
fail-fast: false # Don't fail fast to avoid locking TF State
matrix: ${{ fromJson(needs.atmos-affected.outputs.matrix) }}
## Avoid running the same stack in parallel mode (from different workflows)
concurrency:
group: ${{ matrix.stack_slug }}
cancel-in-progress: false
steps:
- name: Plan Atmos Component
uses: cloudposse/github-action-atmos-terraform-plan@v4
with:
component: ${{ matrix.component }}
stack: ${{ matrix.stack }}
atmos-config-path: ./rootfs/usr/local/etc/atmos/
atmos-version: 1.99.0
```
### Migrating from `v5` to `v6`
The notable changes in `v6` are:
- `v6` works only with `atmos >= 1.99.0`
- `v6` allow to skip internal checkout with `skip-checkout` input
The only required migration step is updating atmos version to `>= 1.80.0`
### Migrating from `v4` to `v5`
The notable changes in `v5` are:
- `v5` works only with `atmos >= 1.80.0`
- `v5` supports atmos templating
The only required migration step is updating atmos version to `>= 1.80.0`
### Migrating from `v3` to `v4`
The notable changes in `v4` are:
- `v4` perform aws authentication assuming `integrations.github.gitops.role.plan` IAM role
No special migration steps required
### Migrating from `v2` to `v3`
The notable changes in `v3` are:
- `v3` works only with `atmos >= 1.63.0`
- `v3` drops `install-terraform` input because terraform is not required for affected stacks call
- `v3` 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 `v2` to `v3`, 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
- id: affected
uses: cloudposse/github-action-atmos-affected-stacks@v3
with:
atmos-config-path: ./rootfs/usr/local/etc/atmos/
atmos-version: 1.63.0
```
This corresponds to the `v2` configuration (deprecated) below.
The `v2` 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 `v2` GitHub Action Workflow looked like this.
`.github/workflows/main.yaml`
```yaml
- id: affected
uses: cloudposse/github-action-atmos-affected-stacks@v2
with:
atmos-gitops-config-path: ./.github/config/atmos-gitops.yaml
```
### Migrating from `v1` to `v2`
`v2` moves most of the `inputs` to the Atmos GitOps config path `./.github/config/atmos-gitops.yaml`. Simply create this file, transfer your settings to it, then remove the corresponding arguments from your invocations of the `cloudposse/github-action-atmos-affected-stacks` action.
| name |
|--------------------------|
| `atmos-version` |
| `atmos-config-path` |
| `terraform-state-bucket` |
| `terraform-state-table` |
| `terraform-state-role` |
| `terraform-plan-role` |
| `terraform-apply-role` |
| `terraform-version` |
| `aws-region` |
| `enable-infracost` |
If you want the same behavior in `v2` as in `v1` you should create config `./.github/config/atmos-gitops.yaml` with the same variables as in `v1` inputs.
```yaml
- name: Determine Affected Stacks
uses: cloudposse/github-action-atmos-affected-stacks@v2
id: affected
with:
atmos-gitops-config-path: ./.github/config/atmos-gitops.yaml
nested-matrices-count: 1
```
Which would produce the same behavior as in `v1`, doing this:
```yaml
- name: Determine Affected Stacks
uses: cloudposse/github-action-atmos-affected-stacks@v1
id: affected
with:
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
```
include:
- "docs/github-action.md"
# Contributors to this project
contributors:
- name: "Matt Calhoun"
github: "mcalhoun"
- name: "Igor Rodionov"
github: "goruha"