forked from PinSpace-Org/GistPin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathterratest.yml
More file actions
115 lines (97 loc) 路 3.03 KB
/
Copy pathterratest.yml
File metadata and controls
115 lines (97 loc) 路 3.03 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
name: Terratest
on:
pull_request:
paths:
- "infrastructure/terraform/**"
push:
branches: [main]
paths:
- "infrastructure/terraform/**"
concurrency:
group: terratest-${{ github.head_ref || github.ref_name }}
cancel-in-progress: true
env:
TF_VERSION: "1.7.5"
GO_VERSION: "1.22"
jobs:
terratest:
name: Run Terratest
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read
pull-requests: write
defaults:
run:
working-directory: infrastructure/terraform/tests
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
cache-dependency-path: infrastructure/terraform/tests/go.sum
- uses: hashicorp/setup-terraform@v3
with:
terraform_version: ${{ env.TF_VERSION }}
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.AWS_CI_ROLE_ARN }}
aws-region: us-east-1
- name: Install dependencies
run: |
go mod download
go mod tidy
- name: Run Terratest
id: terratest
run: |
go test -v -timeout 30m ./... 2>&1 | tee terratest-output.txt
echo "exitcode=${PIPESTATUS[0]}" >> "$GITHUB_OUTPUT"
- name: Upload test output
if: always()
uses: actions/upload-artifact@v4
with:
name: terratest-output-${{ github.run_id }}
path: infrastructure/terraform/tests/terratest-output.txt
retention-days: 30
- name: Post test results to PR
if: github.event_name == 'pull_request'
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const output = fs.readFileSync('infrastructure/terraform/tests/terratest-output.txt', 'utf8');
const body = `### Terratest Results\n\`\`\`\n${output.slice(0, 60000)}\n\`\`\``;
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body,
});
cleanup:
name: Test Cleanup
runs-on: ubuntu-latest
needs: terratest
if: always()
permissions:
id-token: write
contents: read
steps:
- uses: actions/checkout@v4
- uses: hashicorp/setup-terraform@v3
with:
terraform_version: ${{ env.TF_VERSION }}
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.AWS_CI_ROLE_ARN }}
aws-region: us-east-1
- name: Destroy any orphaned resources
working-directory: infrastructure/terraform
run: |
for dir in modules/*/; do
if [ -f "$dir/terraform.tfstate" ]; then
echo "Destroying resources in $dir"
terraform destroy -auto-approve "$dir" || true
fi
done