-
-
Notifications
You must be signed in to change notification settings - Fork 13
/
pr_push_auth.yaml
50 lines (41 loc) · 1.53 KB
/
pr_push_auth.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
---
name: Trigger on pull_request (plan) and push (apply) events with Terraform, AWS authentication and caching.
on:
pull_request:
push:
branches: [main]
jobs:
tf:
runs-on: ubuntu-latest
permissions:
actions: read # Required to identify workflow run.
checks: write # Required to add status summary.
contents: read # Required to checkout repository.
id-token: write # Required to authenticate via OIDC.
pull-requests: write # Required to add comment and label.
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Authenticate AWS
uses: aws-actions/configure-aws-credentials@v4
with:
aws-region: us-east-1
role-to-assume: ${{ secrets.AWS_ROLE }}
- name: Create cache
run: |
mkdir --parents $HOME/.terraform.d/plugin-cache
echo "TF_PLUGIN_CACHE_DIR=$HOME/.terraform.d/plugin-cache" >> $GITHUB_ENV
- name: Cache TF
uses: actions/cache@v4
with:
path: ~/.terraform.d/plugin-cache
key: cache-tf-${{ runner.os }}-${{ hashFiles('path/to/directory/.terraform.lock.hcl') }}
- name: Setup TF
uses: hashicorp/setup-terraform@v3
- name: Provision TF
uses: devsectop/tf-via-pr@v12
with:
command: ${{ github.event_name == 'push' && 'apply' || 'plan' }}
arg-lock: ${{ github.event_name == 'push' }}
working-directory: path/to/directory
plan-encrypt: ${{ secrets.PASSPHRASE }}