|
| 1 | +name: Test CloudFormation Action v2.0.0-beta |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + push: |
| 6 | + branches: [main] |
| 7 | + |
| 8 | +permissions: |
| 9 | + id-token: write # This is required for requesting the JWT |
| 10 | + contents: read # This is required for actions/checkout |
| 11 | + |
| 12 | +jobs: |
| 13 | + test-create-and-execute: |
| 14 | + runs-on: ubuntu-latest |
| 15 | + steps: |
| 16 | + - uses: actions/checkout@v4 |
| 17 | + |
| 18 | + - name: Configure AWS credentials |
| 19 | + uses: aws-actions/configure-aws-credentials@v4 |
| 20 | + with: |
| 21 | + role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }} |
| 22 | + aws-region: us-east-1 |
| 23 | + |
| 24 | + - name: Test with local template and JSON file |
| 25 | + id: deploy-file |
| 26 | + uses: aws-actions/aws-cloudformation-github-deploy@v2.0.0-beta |
| 27 | + with: |
| 28 | + name: test-file-${{ github.run_number }} |
| 29 | + template: stack.yaml |
| 30 | + parameter-overrides: "file:///${{ github.workspace }}/overrides.json" |
| 31 | + |
| 32 | + - name: Test with inline parameters |
| 33 | + id: deploy-inline |
| 34 | + uses: aws-actions/aws-cloudformation-github-deploy@v2.0.0-beta |
| 35 | + with: |
| 36 | + name: test-inline-${{ github.run_number }} |
| 37 | + template: stack.yaml |
| 38 | + parameter-overrides: "Environment=gamma,AList=value1,AList=value2" |
| 39 | + |
| 40 | + test-large-template: |
| 41 | + runs-on: ubuntu-latest |
| 42 | + steps: |
| 43 | + - uses: actions/checkout@v4 |
| 44 | + |
| 45 | + - name: Configure AWS credentials |
| 46 | + uses: aws-actions/configure-aws-credentials@v4 |
| 47 | + with: |
| 48 | + role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }} |
| 49 | + aws-region: us-east-1 |
| 50 | + |
| 51 | + - name: Test with large template (should fail with clean error message) |
| 52 | + id: deploy-large |
| 53 | + uses: aws-actions/aws-cloudformation-github-deploy@v2.0.0-beta |
| 54 | + with: |
| 55 | + name: test-large-${{ github.run_number }} |
| 56 | + template: large-template.yaml |
| 57 | + parameter-overrides: "Environment=test" |
| 58 | + continue-on-error: true |
| 59 | + |
| 60 | + - name: Verify large template error message |
| 61 | + run: | |
| 62 | + echo "Large template test completed (expected to fail)" |
| 63 | + echo "This test verifies that oversized templates produce clean error messages" |
| 64 | +
|
| 65 | + test-validation-error: |
| 66 | + runs-on: ubuntu-latest |
| 67 | + steps: |
| 68 | + - uses: actions/checkout@v4 |
| 69 | + |
| 70 | + - name: Configure AWS credentials |
| 71 | + uses: aws-actions/configure-aws-credentials@v4 |
| 72 | + with: |
| 73 | + role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }} |
| 74 | + aws-region: us-east-1 |
| 75 | + |
| 76 | + - name: Test template with validation error (should fail during change set creation) |
| 77 | + id: deploy-validation-error |
| 78 | + uses: aws-actions/aws-cloudformation-github-deploy@v2.0.0-beta |
| 79 | + with: |
| 80 | + name: test-validation-error-${{ github.run_number }} |
| 81 | + template: validation-error-template.yaml |
| 82 | + parameter-overrides: "Environment=test" |
| 83 | + continue-on-error: true |
| 84 | + |
| 85 | + - name: Verify validation error handling |
| 86 | + run: | |
| 87 | + echo "Validation error test completed (expected to fail during change set creation)" |
| 88 | + echo "This test verifies that template validation errors produce clean error messages" |
| 89 | +
|
| 90 | + test-execution-error: |
| 91 | + runs-on: ubuntu-latest |
| 92 | + steps: |
| 93 | + - uses: actions/checkout@v4 |
| 94 | + |
| 95 | + - name: Configure AWS credentials |
| 96 | + uses: aws-actions/configure-aws-credentials@v4 |
| 97 | + with: |
| 98 | + role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }} |
| 99 | + aws-region: us-east-1 |
| 100 | + |
| 101 | + - name: Test template with execution error (should fail during change set execution) |
| 102 | + id: deploy-execution-error |
| 103 | + uses: aws-actions/aws-cloudformation-github-deploy@v2.0.0-beta |
| 104 | + with: |
| 105 | + name: test-execution-error-${{ github.run_number }} |
| 106 | + template: execution-error-template.yaml |
| 107 | + parameter-overrides: "Environment=test" |
| 108 | + continue-on-error: true |
| 109 | + |
| 110 | + - name: Verify execution error handling |
| 111 | + run: | |
| 112 | + echo "Execution error test completed (expected to fail during change set execution)" |
| 113 | + echo "This test verifies that execution errors produce detailed failure information" |
| 114 | +
|
| 115 | + test-empty-changeset: |
| 116 | + runs-on: ubuntu-latest |
| 117 | + steps: |
| 118 | + - uses: actions/checkout@v4 |
| 119 | + |
| 120 | + - name: Configure AWS credentials |
| 121 | + uses: aws-actions/configure-aws-credentials@v4 |
| 122 | + with: |
| 123 | + role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }} |
| 124 | + aws-region: us-east-1 |
| 125 | + |
| 126 | + - name: Deploy stack first time |
| 127 | + id: deploy-first |
| 128 | + uses: aws-actions/aws-cloudformation-github-deploy@v2.0.0-beta |
| 129 | + with: |
| 130 | + name: test-empty-changeset-${{ github.run_number }} |
| 131 | + template: stack.yaml |
| 132 | + parameter-overrides: "Environment=beta,AList=value1,AList=value2" |
| 133 | + |
| 134 | + - name: Deploy same stack again with default behavior (should succeed on empty changeset) |
| 135 | + id: deploy-second-default |
| 136 | + uses: aws-actions/aws-cloudformation-github-deploy@v2.0.0-beta |
| 137 | + with: |
| 138 | + name: test-empty-changeset-${{ github.run_number }} |
| 139 | + template: stack.yaml |
| 140 | + parameter-overrides: "Environment=beta,AList=value1,AList=value2" |
| 141 | + |
| 142 | + - name: Deploy same stack again with fail-on-empty-changeset=1 (should fail on empty changeset) |
| 143 | + id: deploy-second-fail |
| 144 | + uses: aws-actions/aws-cloudformation-github-deploy@v2.0.0-beta |
| 145 | + with: |
| 146 | + name: test-empty-changeset-${{ github.run_number }} |
| 147 | + template: stack.yaml |
| 148 | + parameter-overrides: "Environment=beta,AList=value1,AList=value2" |
| 149 | + fail-on-empty-changeset: "1" |
| 150 | + continue-on-error: true |
| 151 | + |
| 152 | + - name: Verify empty changeset behavior |
| 153 | + run: | |
| 154 | + echo "Empty changeset test completed" |
| 155 | + echo "First deployment: ${{ steps.deploy-first.outputs.stack-id }}" |
| 156 | + echo "Second deployment (default): ${{ steps.deploy-second-default.outputs.stack-id }}" |
| 157 | + echo "Third deployment (fail flag): Expected to fail" |
| 158 | + echo "This verifies v2 behavior: empty changesets succeed by default, fail when flag is set" |
| 159 | +
|
| 160 | + test-create-only-then-execute: |
| 161 | + runs-on: ubuntu-latest |
| 162 | + steps: |
| 163 | + - uses: actions/checkout@v4 |
| 164 | + |
| 165 | + - name: Configure AWS credentials |
| 166 | + uses: aws-actions/configure-aws-credentials@v4 |
| 167 | + with: |
| 168 | + role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }} |
| 169 | + aws-region: us-east-1 |
| 170 | + |
| 171 | + - name: Create change set for review |
| 172 | + id: create-cs |
| 173 | + uses: aws-actions/aws-cloudformation-github-deploy@v2.0.0-beta |
| 174 | + with: |
| 175 | + mode: "create-only" |
| 176 | + name: test-two-step-${{ github.run_number }} |
| 177 | + template: stack.yaml |
| 178 | + parameter-overrides: "Environment=prod,AList=prod1,AList=prod2" |
| 179 | + |
| 180 | + - name: Review change set outputs |
| 181 | + run: | |
| 182 | + echo "Change Set ID: ${{ steps.create-cs.outputs.change-set-id }}" |
| 183 | + echo "Has Changes: ${{ steps.create-cs.outputs.has-changes }}" |
| 184 | + echo "Changes Count: ${{ steps.create-cs.outputs.changes-count }}" |
| 185 | + echo "Changes Summary: ${{ steps.create-cs.outputs.changes-summary }}" |
| 186 | +
|
| 187 | + - name: Execute change set |
| 188 | + if: steps.create-cs.outputs.has-changes == 'true' |
| 189 | + uses: aws-actions/aws-cloudformation-github-deploy@v2.0.0-beta |
| 190 | + with: |
| 191 | + mode: "execute-only" |
| 192 | + name: test-two-step-${{ github.run_number }} |
| 193 | + execute-change-set-id: ${{ steps.create-cs.outputs.change-set-id }} |
| 194 | + |
| 195 | + test-drift-detection: |
| 196 | + runs-on: ubuntu-latest |
| 197 | + steps: |
| 198 | + - uses: actions/checkout@v4 |
| 199 | + |
| 200 | + - name: Configure AWS credentials |
| 201 | + uses: aws-actions/configure-aws-credentials@v4 |
| 202 | + with: |
| 203 | + role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }} |
| 204 | + aws-region: us-east-1 |
| 205 | + |
| 206 | + - name: Deploy initial stack for drift testing |
| 207 | + uses: aws-actions/aws-cloudformation-github-deploy@v2.0.0-beta |
| 208 | + with: |
| 209 | + name: test-drift-${{ github.run_number }} |
| 210 | + template: drift-test.yaml |
| 211 | + parameter-overrides: "RunNumber=${{ github.run_number }}" |
| 212 | + |
| 213 | + - name: Introduce drift by manually changing parameter |
| 214 | + run: | |
| 215 | + # Debug: Check if parameter exists |
| 216 | + echo "Checking if parameter exists..." |
| 217 | + aws ssm describe-parameters --parameter-filters "Key=Name,Values=/test/drift-${{ github.run_number }}" || echo "Parameter not found" |
| 218 | + |
| 219 | + # Debug: List all parameters with our prefix |
| 220 | + echo "Listing parameters with /test/drift prefix..." |
| 221 | + aws ssm describe-parameters --parameter-filters "Key=Name,Option=BeginsWith,Values=/test/drift" || echo "No parameters found" |
| 222 | + |
| 223 | + # Add a tag outside of CloudFormation to create drift |
| 224 | + echo "Adding tags to parameter..." |
| 225 | + aws ssm add-tags-to-resource \ |
| 226 | + --resource-type Parameter \ |
| 227 | + --resource-id /test/drift-${{ github.run_number }} \ |
| 228 | + --tags Key=ManualTag,Value=added-outside-cfn |
| 229 | + |
| 230 | + # Change the parameter value to create more drift |
| 231 | + echo "Updating parameter value..." |
| 232 | + aws ssm put-parameter \ |
| 233 | + --name /test/drift-${{ github.run_number }} \ |
| 234 | + --value "manually-changed-value" \ |
| 235 | + --overwrite |
| 236 | +
|
| 237 | + - name: Create drift-reverting change set |
| 238 | + id: drift-cs |
| 239 | + uses: aws-actions/aws-cloudformation-github-deploy@v2.0.0-beta |
| 240 | + with: |
| 241 | + mode: "create-only" |
| 242 | + name: test-drift-${{ github.run_number }} |
| 243 | + template: drift-test.yaml |
| 244 | + parameter-overrides: "RunNumber=${{ github.run_number }}" |
| 245 | + deployment-mode: "REVERT_DRIFT" |
| 246 | + |
| 247 | + - name: Review drift change set |
| 248 | + run: | |
| 249 | + echo "Drift Change Set ID: ${{ steps.drift-cs.outputs.change-set-id }}" |
| 250 | + echo "Has Changes: ${{ steps.drift-cs.outputs.has-changes }}" |
| 251 | + echo "Changes Count: ${{ steps.drift-cs.outputs.changes-count }}" |
| 252 | + echo "Changes Summary: ${{ steps.drift-cs.outputs.changes-summary }}" |
| 253 | +
|
| 254 | + - name: Execute drift-reverting change set |
| 255 | + uses: aws-actions/aws-cloudformation-github-deploy@v2.0.0-beta |
| 256 | + with: |
| 257 | + mode: "execute-only" |
| 258 | + name: test-drift-${{ github.run_number }} |
| 259 | + execute-change-set-id: ${{ steps.drift-cs.outputs.change-set-id }} |
| 260 | + |
| 261 | + test-long-running: |
| 262 | + runs-on: ubuntu-latest |
| 263 | + timeout-minutes: 120 |
| 264 | + steps: |
| 265 | + - uses: actions/checkout@v4 |
| 266 | + |
| 267 | + - name: Configure AWS credentials |
| 268 | + uses: aws-actions/configure-aws-credentials@v4 |
| 269 | + with: |
| 270 | + role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }} |
| 271 | + aws-region: us-east-1 |
| 272 | + role-duration-seconds: 7200 |
| 273 | + |
| 274 | + - name: Test long-running stack (70 minutes) |
| 275 | + uses: aws-actions/aws-cloudformation-github-deploy@v2.0.0-beta |
| 276 | + with: |
| 277 | + name: test-long-running-${{ github.run_number }} |
| 278 | + template: long-running-stack.yaml |
| 279 | + capabilities: "CAPABILITY_IAM" |
| 280 | + timeout-in-minutes: 90 |
| 281 | + |
| 282 | + cleanup: |
| 283 | + runs-on: ubuntu-latest |
| 284 | + 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] |
| 285 | + if: always() |
| 286 | + steps: |
| 287 | + - name: Configure AWS credentials |
| 288 | + uses: aws-actions/configure-aws-credentials@v4 |
| 289 | + with: |
| 290 | + role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }} |
| 291 | + aws-region: us-east-1 |
| 292 | + |
| 293 | + - name: Cleanup test stacks |
| 294 | + run: | |
| 295 | + # Find all test stacks for this run |
| 296 | + stacks=$(aws cloudformation list-stacks \ |
| 297 | + --query "StackSummaries[?contains(StackName, 'test-') && contains(StackName, '${{ github.run_number }}') && StackStatus != 'DELETE_COMPLETE'].StackName" \ |
| 298 | + --output text) |
| 299 | + |
| 300 | + if [ ! -z "$stacks" ]; then |
| 301 | + echo "Found stacks to delete: $stacks" |
| 302 | + echo "$stacks" | tr '\t' '\n' | while read stack; do |
| 303 | + if [ ! -z "$stack" ]; then |
| 304 | + echo "Deleting stack: $stack" |
| 305 | + aws cloudformation delete-stack --stack-name "$stack" |
| 306 | + fi |
| 307 | + done |
| 308 | + |
| 309 | + # Wait for all deletions to complete |
| 310 | + echo "Waiting for stack deletions to complete..." |
| 311 | + echo "$stacks" | tr '\t' '\n' | while read stack; do |
| 312 | + if [ ! -z "$stack" ]; then |
| 313 | + echo "Waiting for $stack to delete..." |
| 314 | + aws cloudformation wait stack-delete-complete --stack-name "$stack" || echo "Stack $stack deletion failed or timed out" |
| 315 | + fi |
| 316 | + done |
| 317 | + else |
| 318 | + echo "No stacks found to delete" |
| 319 | + fi |
| 320 | +
|
| 321 | + - name: Cleanup SSM parameters |
| 322 | + run: | |
| 323 | + # Clean up all test parameters for this run |
| 324 | + echo "Cleaning up SSM parameters..." |
| 325 | + aws ssm describe-parameters \ |
| 326 | + --parameter-filters "Key=Name,Option=BeginsWith,Values=/test/" \ |
| 327 | + --query "Parameters[?contains(Name, '${{ github.run_number }}')].Name" \ |
| 328 | + --output text | tr '\t' '\n' | while read param; do |
| 329 | + if [ ! -z "$param" ]; then |
| 330 | + echo "Deleting parameter: $param" |
| 331 | + aws ssm delete-parameter --name "$param" || echo "Parameter $param already deleted" |
| 332 | + fi |
| 333 | + done |
0 commit comments