-
-
Notifications
You must be signed in to change notification settings - Fork 4
243 lines (183 loc) · 7.74 KB
/
test-changes-exists-drift.yml
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
name: "Test - Changes exists - Drift"
on:
workflow_dispatch: {}
env:
AWS_REGION: us-east-2
# Permissions required for assuming AWS identity
permissions:
id-token: write
contents: read
jobs:
setup:
runs-on: ubuntu-latest
steps:
- name: Setup
run: echo "Do setup"
test:
runs-on: ubuntu-latest
continue-on-error: true
needs: [setup]
steps:
- uses: actions/checkout@v4
# with:
# ref: ${{ github.event.pull_request.head.ref }}
- shell: bash
run: |
mkdir -p ${{ runner.temp }}
cp ./tests/opentofu/atmos.yaml ${{ runner.temp }}/atmos.yaml
for file in ./tests/opentofu/stacks/catalog/*.yaml; do
if [ -f "$file" ]; then
sed -i -e "s#__INFRACOST_ENABLED__#false#g" "$file"
sed -i -e "s#__STORAGE_REGION__#${{ env.AWS_REGION }}#g" "$file"
sed -i -e "s#__STORAGE_BUCKET__#${{ secrets.TERRAFORM_STATE_BUCKET }}#g" "$file"
sed -i -e "s#__STORAGE_TABLE__#${{ secrets.TERRAFORM_STATE_TABLE }}#g" "$file"
sed -i -e "s#__STORAGE_TABLE__#${{ secrets.TERRAFORM_STATE_TABLE }}#g" "$file"
sed -i -e "s#__STORAGE_ROLE__#${{ secrets.TERRAFORM_STATE_ROLE }}#g" "$file"
sed -i -e "s#__PLAN_ROLE__#${{ secrets.TERRAFORM_PLAN_ROLE }}#g" "$file"
sed -i -e "s#__APPLY_ROLE__#${{ secrets.TERRAFORM_PLAN_ROLE }}#g" "$file"
fi
done
- name: Plan Atmos Component
id: current
uses: ./
with:
component: "foobar/changes"
stack: "plat-ue2-sandbox"
sha: ${{ github.sha }}
drift-detection-mode-enabled: true
atmos-config-path: ${{ runner.temp }}
atmos-version: 1.99.0
skip-checkout: true
outputs:
result: ${{ steps.current.outcome }}
summary: ${{ steps.current.outputs.summary }}
assert:
runs-on: ubuntu-latest
needs: [test]
steps:
- uses: nick-fields/assert-action@v2
with:
expected: 'success'
actual: "${{ needs.test.outputs.result }}"
- name: Download Artifacts
uses: actions/download-artifact@v4
with:
path: metadata
pattern: metadata-*
merge-multiple: true
- name: Display structure of downloaded files
id: metadata
run: |
set +e
test -d ./metadata
DIR_EXISTS=$?
echo "dir_exists=${DIR_EXISTS}" >> $GITHUB_OUTPUT
test -f ./metadata/plat-ue2-sandbox-foobar_changes.metadata.json
FILE_EXISTS=$?
echo "file_exists=${FILE_EXISTS}" >> $GITHUB_OUTPUT
test -f ./metadata/step-summary-plat-ue2-sandbox-foobar_changes.md
FILE_EXISTS=$?
echo "file_summary_md_exists=${FILE_EXISTS}" >> $GITHUB_OUTPUT
test -f ./metadata/issue-description-plat-ue2-sandbox-foobar_changes.md
FILE_EXISTS=$?
echo "file_md_exists=${FILE_EXISTS}" >> $GITHUB_OUTPUT
echo "file_md=$(cat ./metadata/issue-description-plat-ue2-sandbox-foobar_changes.md | jq -Rs .)" >> $GITHUB_OUTPUT
echo "file_json=$(cat ./metadata/plat-ue2-sandbox-foobar_changes.metadata.json | jq -Rs . )" >> $GITHUB_OUTPUT
echo files_json_count=$(ls -lA ./metadata/*.json | wc -l) >> $GITHUB_OUTPUT
- uses: nick-fields/assert-action@v2
with:
actual: "${{ steps.metadata.outputs.dir_exists }}"
expected: "0"
- uses: nick-fields/assert-action@v2
with:
actual: "${{ steps.metadata.outputs.file_exists }}"
expected: "0"
- uses: nick-fields/assert-action@v2
with:
actual: "${{ steps.metadata.outputs.file_md_exists }}"
expected: "0"
- uses: nick-fields/assert-action@v2
with:
actual: "${{ steps.metadata.outputs.file_summary_md_exists }}"
expected: "0"
- uses: nick-fields/assert-action@v2
with:
actual: "${{ fromJSON(needs.test.outputs.summary) }}"
expected: "${{ fromJSON(steps.metadata.outputs.file_md) }}"
- uses: nick-fields/assert-action@v2
with:
actual: "${{ steps.metadata.outputs.files_json_count }}"
expected: "1"
- uses: nick-fields/assert-action@v2
with:
actual: "${{ fromJSON(steps.metadata.outputs.file_json) }}"
expected: |
{ "stack": "plat-ue2-sandbox", "component": "foobar/changes", "componentPath": "tests/opentofu/components/terraform/foobar", "drifted": true, "error": false }
- uses: nick-fields/assert-action@v2
with:
actual: "${{ fromJSON(needs.test.outputs.summary) }}"
expected: |
## Drift Detected for `foobar/changes` in `plat-ue2-sandbox`
<a href="https://cloudposse.com/"><img src="https://cloudposse.com/logo-300x69.svg" width="100px" align="right"/></a>
[![create](https://shields.io/badge/PLAN-CREATE-success?style=for-the-badge)](#user-content-create-plat-ue2-sandbox-foobar_changes)
<details><summary><a id="result-plat-ue2-sandbox-foobar_changes" />Plan: 1 to add, 0 to change, 0 to destroy.</summary>
<br/>
To reproduce this locally, run:<br/><br/>
```shell
atmos terraform plan foobar/changes -s plat-ue2-sandbox
```
---
### <a id="create-plat-ue2-sandbox-foobar_changes" />Create
```diff
+ random_id.foo[0]
```
</details>
<details><summary>Terraform <strong>Plan</strong> Summary</summary>
```hcl
# random_id.foo[0] will be created
+ resource "random_id" "foo" {
+ b64_std = (known after apply)
+ b64_url = (known after apply)
+ byte_length = 8
+ dec = (known after apply)
+ hex = (known after apply)
+ id = (known after apply)
+ keepers = {
+ "seed" = "foo-plat-ue2-sandbox-blue"
}
}
Plan: 1 to add, 0 to change, 0 to destroy.
Warning: Test warning summary
with data.validation_warning.warn[0],
on main.tf line 20, in data "validation_warning" "warn":
20: data "validation_warning" "warn" {
Test warning details
```
</details>
> [!WARNING]
> ```
> Warning: Test warning summary
>
> with data.validation_warning.warn[0],
> on main.tf line 20, in data "validation_warning" "warn":
> 20: data "validation_warning" "warn" {
>
> Test warning details
> ```
<details><summary>Metadata</summary>
```json
{
"component": "foobar/changes",
"stack": "plat-ue2-sandbox",
"componentPath": "tests/opentofu/components/terraform/foobar",
"commitSHA": "${{ github.sha }}"
}
```
</details>
teardown:
runs-on: ubuntu-latest
needs: [assert]
if: ${{ always() }}
steps:
- name: Tear down
run: echo "Do Tear down"