11---
2- name : Terraform Terratest with Go
3- on : # yamllint disable-line rule:truthy
4- pull_request :
5- types : [opened]
6- workflow_dispatch :
7- inputs :
8- pr_number :
9- description : ' Pull Request Number'
10- required : true
11-
12- permissions :
13- id-token : write
14- contents : read
15- statuses : write # Required for setting commit status
16-
17- jobs :
18- terratest :
19- runs-on : ubuntu-latest
20- name : Terratest Checks
21-
22- env :
23- PR_NUMBER : >-
24- ${{ github.event_name == 'workflow_dispatch' &&
25- github.event.inputs.pr_number || github.event.pull_request.number }}
26-
27-
28- steps :
29- - name : Checkout PR code
30- uses : actions/checkout@v4
31- with :
32- ref : refs/pull/${{ env.PR_NUMBER }}/head
33-
34- - name : Configure AWS credentials via OIDC
35- uses : aws-actions/configure-aws-credentials@v4
36- with :
37- role-to-assume : ${{ secrets.ARC_IAC_TERRATEST_ROLE }}
38- aws-region : us-east-1
39-
40- - name : Set up Go
41- uses : actions/setup-go@v5
42- with :
43- go-version : ' 1.24'
44-
45- - name : Set up Terraform
46- uses : hashicorp/setup-terraform@v3
47- with :
48- terraform_version : 1.5.7
49- terraform_wrapper : false
50-
51- - name : Create test directory and download go from S3
52- run : |
53- mkdir -p terra-test
54- aws s3 cp ${{ secrets.ARC_TERRATEST_GO_FILE }} terra-test/terra_test.go
55- - name : Initialize Go module and install dependencies
56- run : |
57- cd terra-test
58- ls
59- go mod init terraform-test || true
60- go get github.com/gruntwork-io/terratest/modules/terraform
61- go get github.com/stretchr/testify/assert
62- go mod tidy
63- go test -v -timeout 40m
64- - name : Report check status manually
65- uses : actions/github-script@v7
66- with :
67- github-token : ${{ secrets.GITHUB_TOKEN }}
68- script : |
69- const pr_number = parseInt(process.env.PR_NUMBER);
70- const pr = await github.rest.pulls.get({
71- owner: context.repo.owner,
72- repo: context.repo.repo,
73- pull_number: pr_number,
74- });
75- const sha = pr.data.head.sha;
76- await github.rest.repos.createCommitStatus({
77- owner: context.repo.owner,
78- repo: context.repo.repo,
79- sha: sha,
80- state: 'success',
81- context: 'terratest',
82- description: 'Manual terratest completed successfully',
83- target_url:
84- `https://github.com/${context.repo.owner}/${context.repo.repo}` +
85- `/actions/runs/${process.env.GITHUB_RUN_ID}`,
86- });
2+ name : Terraform Terratest with Go
3+ on : # yamllint disable-line rule:truthy
4+ pull_request :
5+ types : [opened]
6+ workflow_dispatch :
7+ inputs :
8+ pr_number :
9+ description : ' Pull Request Number'
10+ required : true
11+
12+ permissions :
13+ id-token : write
14+ contents : read
15+ statuses : write # Required for setting commit status
16+
17+ jobs :
18+ terratest :
19+ runs-on : ubuntu-latest
20+ name : Terratest Checks
21+
22+ env :
23+ PR_NUMBER : >-
24+ ${{ github.event_name == 'workflow_dispatch' &&
25+ github.event.inputs.pr_number || github.event.pull_request.number }}
26+
27+
28+ steps :
29+ - name : Checkout PR code
30+ uses : actions/checkout@v4
31+ with :
32+ ref : refs/pull/${{ env.PR_NUMBER }}/head
33+
34+ - name : Configure AWS credentials via OIDC
35+ uses : aws-actions/configure-aws-credentials@v2
36+ with :
37+ role-to-assume : ${{ secrets.ARC_IAC_TERRATEST_ROLE }}
38+ aws-region : us-east-1
39+
40+ - name : Set up Go
41+ uses : actions/setup-go@v4
42+ with :
43+ go-version : ' 1.24'
44+
45+ - name : Set up Terraform
46+ uses : hashicorp/setup-terraform@v2
47+ with :
48+ terraform_version : 1.7
49+ terraform_wrapper : false
50+
51+ - name : Create test directory and download go from S3
52+ run : |
53+ mkdir -p terra-test
54+ aws s3 cp ${{ secrets.ARC_TERRATEST_GO_FILE }} terra-test/terra_test.go
55+ - name : Initialize Go module and install dependencies
56+ run : |
57+ cd terra-test
58+ ls
59+ go mod init terraform-test || true
60+ go get github.com/gruntwork-io/terratest/modules/terraform
61+ go get github.com/stretchr/testify/assert
62+ go mod tidy
63+ go test -v -timeout 40m
64+ - name : Report check status manually
65+ uses : actions/github-script@v7
66+ with :
67+ github-token : ${{ secrets.GITHUB_TOKEN }}
68+ script : |
69+ const pr_number = parseInt(process.env.PR_NUMBER);
70+ const pr = await github.rest.pulls.get({
71+ owner: context.repo.owner,
72+ repo: context.repo.repo,
73+ pull_number: pr_number,
74+ });
75+ const sha = pr.data.head.sha;
76+ await github.rest.repos.createCommitStatus({
77+ owner: context.repo.owner,
78+ repo: context.repo.repo,
79+ sha: sha,
80+ state: 'success',
81+ context: 'terratest',
82+ description: 'Manual terratest completed successfully',
83+ target_url:
84+ `https://github.com/${context.repo.owner}/${context.repo.repo}` +
85+ `/actions/runs/${process.env.GITHUB_RUN_ID}`,
86+ });
87+
88+
89+
90+
91+
92+
93+
0 commit comments