This repository has been archived by the owner on Mar 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
78 lines (65 loc) · 2.24 KB
/
tf-plan-dev.yaml
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
name: Terraform Plan Development Environment
on:
pull_request:
branches:
- main
paths:
- 'dev/**'
defaults:
run:
working-directory: ./dev
permissions:
pull-requests: write
jobs:
terraform_plan:
if: github.repository == 'dpgraham-com/dpgraham-infra'
name: Terraform Plan
environment: development
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
id-token: 'write'
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Terraform
uses: hashicorp/setup-terraform@v2
- name: Authenticate Google Cloud
uses: google-github-actions/auth@v1
id: auth
with:
workload_identity_provider: ${{ secrets.WIF_PROVIDER }}
service_account: ${{ secrets.SA_EMAIL }}
- name: Terraform Init
run: terraform init -input=false -no-color
- name: Terraform Plan
id: plan
run: terraform plan -input=false -no-color -out=tfplan
env:
TF_VAR_db_name: ${{ secrets.DB_NAME }}
TF_VAR_db_username: ${{ secrets.DB_USERNAME }}
TF_VAR_db_password: ${{ secrets.DB_PASSWORD }}
TF_VAR_cloud_infra_sa: ${{ secrets.CLOUD_INFRA_SA }}
TF_VAR_cloud_run_sa: ${{ secrets.CLOUD_RUN_SA }}
- name: Comment on PR
uses: actions/github-script@v6
if: github.event_name == 'pull_request'
env:
PLAN: "terraform\n${{ steps.plan.outputs.stdout }}"
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const output = `#### Terraform Plan 📖\`${{ steps.plan.outcome }}\`
<details><summary>Show Plan</summary>
\`\`\`\n
${process.env.PLAN}
\`\`\`
</details>
*Pusher: @${{ github.actor }}, Action: \`${{ github.event_name }}\`, Working Directory: \`${{ env.tf_actions_working_dir }}\`, Workflow: \`${{ github.workflow }}\`*`;
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: output
})