-
Notifications
You must be signed in to change notification settings - Fork 0
333 lines (286 loc) · 12.8 KB
/
develop.yaml
File metadata and controls
333 lines (286 loc) · 12.8 KB
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
name: Test CloudFormation Action v2.0.0-beta
on:
workflow_dispatch:
push:
branches: [main]
permissions:
id-token: write # This is required for requesting the JWT
contents: read # This is required for actions/checkout
jobs:
test-create-and-execute:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }}
aws-region: us-east-1
- name: Test with local template and JSON file
id: deploy-file
uses: aws-actions/aws-cloudformation-github-deploy@v2.0.0-beta
with:
name: test-file-${{ github.run_number }}
template: stack.yaml
parameter-overrides: "file:///${{ github.workspace }}/overrides.json"
- name: Test with inline parameters
id: deploy-inline
uses: aws-actions/aws-cloudformation-github-deploy@v2.0.0-beta
with:
name: test-inline-${{ github.run_number }}
template: stack.yaml
parameter-overrides: "Environment=gamma,AList=value1,AList=value2"
test-large-template:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }}
aws-region: us-east-1
- name: Test with large template (should fail with clean error message)
id: deploy-large
uses: aws-actions/aws-cloudformation-github-deploy@v2.0.0-beta
with:
name: test-large-${{ github.run_number }}
template: large-template.yaml
parameter-overrides: "Environment=test"
continue-on-error: true
- name: Verify large template error message
run: |
echo "Large template test completed (expected to fail)"
echo "This test verifies that oversized templates produce clean error messages"
test-validation-error:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }}
aws-region: us-east-1
- name: Test template with validation error (should fail during change set creation)
id: deploy-validation-error
uses: aws-actions/aws-cloudformation-github-deploy@v2.0.0-beta
with:
name: test-validation-error-${{ github.run_number }}
template: validation-error-template.yaml
parameter-overrides: "Environment=test"
continue-on-error: true
- name: Verify validation error handling
run: |
echo "Validation error test completed (expected to fail during change set creation)"
echo "This test verifies that template validation errors produce clean error messages"
test-execution-error:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }}
aws-region: us-east-1
- name: Test template with execution error (should fail during change set execution)
id: deploy-execution-error
uses: aws-actions/aws-cloudformation-github-deploy@v2.0.0-beta
with:
name: test-execution-error-${{ github.run_number }}
template: execution-error-template.yaml
parameter-overrides: "Environment=test"
continue-on-error: true
- name: Verify execution error handling
run: |
echo "Execution error test completed (expected to fail during change set execution)"
echo "This test verifies that execution errors produce detailed failure information"
test-empty-changeset:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }}
aws-region: us-east-1
- name: Deploy stack first time
id: deploy-first
uses: aws-actions/aws-cloudformation-github-deploy@v2.0.0-beta
with:
name: test-empty-changeset-${{ github.run_number }}
template: stack.yaml
parameter-overrides: "Environment=beta,AList=value1,AList=value2"
- name: Deploy same stack again with default behavior (should succeed on empty changeset)
id: deploy-second-default
uses: aws-actions/aws-cloudformation-github-deploy@v2.0.0-beta
with:
name: test-empty-changeset-${{ github.run_number }}
template: stack.yaml
parameter-overrides: "Environment=beta,AList=value1,AList=value2"
- name: Deploy same stack again with fail-on-empty-changeset=1 (should fail on empty changeset)
id: deploy-second-fail
uses: aws-actions/aws-cloudformation-github-deploy@v2.0.0-beta
with:
name: test-empty-changeset-${{ github.run_number }}
template: stack.yaml
parameter-overrides: "Environment=beta,AList=value1,AList=value2"
fail-on-empty-changeset: "1"
continue-on-error: true
- name: Verify empty changeset behavior
run: |
echo "Empty changeset test completed"
echo "First deployment: ${{ steps.deploy-first.outputs.stack-id }}"
echo "Second deployment (default): ${{ steps.deploy-second-default.outputs.stack-id }}"
echo "Third deployment (fail flag): Expected to fail"
echo "This verifies v2 behavior: empty changesets succeed by default, fail when flag is set"
test-create-only-then-execute:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }}
aws-region: us-east-1
- name: Create change set for review
id: create-cs
uses: aws-actions/aws-cloudformation-github-deploy@v2.0.0-beta
with:
mode: "create-only"
name: test-two-step-${{ github.run_number }}
template: stack.yaml
parameter-overrides: "Environment=prod,AList=prod1,AList=prod2"
- name: Review change set outputs
run: |
echo "Change Set ID: ${{ steps.create-cs.outputs.change-set-id }}"
echo "Has Changes: ${{ steps.create-cs.outputs.has-changes }}"
echo "Changes Count: ${{ steps.create-cs.outputs.changes-count }}"
echo "Changes Summary: ${{ steps.create-cs.outputs.changes-summary }}"
- name: Execute change set
if: steps.create-cs.outputs.has-changes == 'true'
uses: aws-actions/aws-cloudformation-github-deploy@v2.0.0-beta
with:
mode: "execute-only"
name: test-two-step-${{ github.run_number }}
execute-change-set-id: ${{ steps.create-cs.outputs.change-set-id }}
test-drift-detection:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }}
aws-region: us-east-1
- name: Deploy initial stack for drift testing
uses: aws-actions/aws-cloudformation-github-deploy@v2.0.0-beta
with:
name: test-drift-${{ github.run_number }}
template: drift-test.yaml
parameter-overrides: "RunNumber=${{ github.run_number }}"
- name: Introduce drift by manually changing parameter
run: |
# Debug: Check if parameter exists
echo "Checking if parameter exists..."
aws ssm describe-parameters --parameter-filters "Key=Name,Values=/test/drift-${{ github.run_number }}" || echo "Parameter not found"
# Debug: List all parameters with our prefix
echo "Listing parameters with /test/drift prefix..."
aws ssm describe-parameters --parameter-filters "Key=Name,Option=BeginsWith,Values=/test/drift" || echo "No parameters found"
# Add a tag outside of CloudFormation to create drift
echo "Adding tags to parameter..."
aws ssm add-tags-to-resource \
--resource-type Parameter \
--resource-id /test/drift-${{ github.run_number }} \
--tags Key=ManualTag,Value=added-outside-cfn
# Change the parameter value to create more drift
echo "Updating parameter value..."
aws ssm put-parameter \
--name /test/drift-${{ github.run_number }} \
--value "manually-changed-value" \
--overwrite
- name: Create drift-reverting change set
id: drift-cs
uses: aws-actions/aws-cloudformation-github-deploy@v2.0.0-beta
with:
mode: "create-only"
name: test-drift-${{ github.run_number }}
template: drift-test.yaml
parameter-overrides: "RunNumber=${{ github.run_number }}"
deployment-mode: "REVERT_DRIFT"
- name: Review drift change set
run: |
echo "Drift Change Set ID: ${{ steps.drift-cs.outputs.change-set-id }}"
echo "Has Changes: ${{ steps.drift-cs.outputs.has-changes }}"
echo "Changes Count: ${{ steps.drift-cs.outputs.changes-count }}"
echo "Changes Summary: ${{ steps.drift-cs.outputs.changes-summary }}"
- name: Execute drift-reverting change set
uses: aws-actions/aws-cloudformation-github-deploy@v2.0.0-beta
with:
mode: "execute-only"
name: test-drift-${{ github.run_number }}
execute-change-set-id: ${{ steps.drift-cs.outputs.change-set-id }}
test-long-running:
runs-on: ubuntu-latest
timeout-minutes: 120
steps:
- uses: actions/checkout@v4
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }}
aws-region: us-east-1
role-duration-seconds: 7200
- name: Test long-running stack (70 minutes)
uses: aws-actions/aws-cloudformation-github-deploy@v2.0.0-beta
with:
name: test-long-running-${{ github.run_number }}
template: long-running-stack.yaml
capabilities: "CAPABILITY_IAM"
timeout-in-minutes: 90
cleanup:
runs-on: ubuntu-latest
needs: [test-create-and-execute, test-large-template, test-validation-error, test-execution-error, test-create-only-then-execute, test-drift-detection, test-long-running]
if: always()
steps:
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }}
aws-region: us-east-1
- name: Cleanup test stacks
run: |
# Find all test stacks for this run
stacks=$(aws cloudformation list-stacks \
--query "StackSummaries[?contains(StackName, 'test-') && contains(StackName, '${{ github.run_number }}') && StackStatus != 'DELETE_COMPLETE'].StackName" \
--output text)
if [ ! -z "$stacks" ]; then
echo "Found stacks to delete: $stacks"
echo "$stacks" | tr '\t' '\n' | while read stack; do
if [ ! -z "$stack" ]; then
echo "Deleting stack: $stack"
aws cloudformation delete-stack --stack-name "$stack"
fi
done
# Wait for all deletions to complete
echo "Waiting for stack deletions to complete..."
echo "$stacks" | tr '\t' '\n' | while read stack; do
if [ ! -z "$stack" ]; then
echo "Waiting for $stack to delete..."
aws cloudformation wait stack-delete-complete --stack-name "$stack" || echo "Stack $stack deletion failed or timed out"
fi
done
else
echo "No stacks found to delete"
fi
- name: Cleanup SSM parameters
run: |
# Clean up all test parameters for this run
echo "Cleaning up SSM parameters..."
aws ssm describe-parameters \
--parameter-filters "Key=Name,Option=BeginsWith,Values=/test/" \
--query "Parameters[?contains(Name, '${{ github.run_number }}')].Name" \
--output text | tr '\t' '\n' | while read param; do
if [ ! -z "$param" ]; then
echo "Deleting parameter: $param"
aws ssm delete-parameter --name "$param" || echo "Parameter $param already deleted"
fi
done