1+ name : Build
2+ on :
3+ push :
4+ branches :
5+ - master
6+ - develop
7+ pull_request :
8+ types : [opened, synchronize, reopened]
9+
10+ terraform :
11+ strategy :
12+ matrix :
13+ path : [src/terraform/cluster, src/terraform/workload-identity]
14+ runs-on : ubuntu-latest
15+ steps :
16+ - uses : actions/checkout@v3
17+ - name : HashiCorp - Setup Terraform
18+ 19+ - run : terraform fmt -check
20+ id : fmt
21+ working-directory : ${{ matrix.path }}
22+ - run : terraform init
23+ working-directory : ${{ matrix.path }}
24+ id : init
25+ - run : terraform validate -no-color
26+ working-directory : ${{ matrix.path }}
27+ id : validate
28+ - name : ' Authenticate to Google Cloud'
29+ uses : ' google-github-actions/auth@v1'
30+ with :
31+ credentials_json : ' ${{ secrets.SA }}'
32+ - name : Replace project-id
33+ uses : jacobtomlinson/gha-find-replace@v2
34+ with :
35+ find : " <dev-stage-project-id>"
36+ replace : ${{ secrets.PROJECT_ID }}
37+ include : " src/terraform/**"
38+ regex : false
39+ - name : Terraform Plan
40+ id : plan
41+ if : matrix.path == 'src/terraform/cluster'
42+ run : terraform plan -var-file=vars/dev.tfvars -no-color
43+ working-directory : ${{ matrix.path }}
44+ - uses : actions/github-script@v6
45+ if : github.event_name == 'pull_request'
46+ with :
47+ github-token : ${{ secrets.GITHUB_TOKEN }}
48+ script : |
49+ const output = `#### Working Directory: ${{ matrix.path }}
50+
51+ #### Terraform Format and Style \`${{ steps.fmt.outcome }}\`
52+
53+ #### Terraform Initialization \`${{ steps.init.outcome }}\`
54+
55+ #### Terraform Validation \`${{ steps.validate.outcome }}\`
56+
57+ <details><summary>Validation Output</summary>
58+
59+ \`\`\`\n
60+ ${{ steps.validate.outputs.stdout }}
61+ \`\`\`
62+
63+ </details>
64+
65+ #### Terraform Plan \`${{ steps.plan.outcome }}\`
66+
67+ <details><summary>Show Plan</summary>
68+
69+ \`\`\`\n
70+ ${{ steps.plan.outputs.stdout }}
71+ \`\`\`
72+
73+ </details>`;
74+
75+ github.rest.issues.createComment({
76+ issue_number: context.issue.number,
77+ owner: context.repo.owner,
78+ repo: context.repo.repo,
79+ body: output
80+ });
81+
82+
0 commit comments