-
-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathpr_self_hosted.yaml
51 lines (42 loc) · 1.7 KB
/
pr_self_hosted.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
---
name: Trigger on pull_request (plan or apply) and labeled (manual) events on self-hosted Terraform and OpenTofu.
on:
pull_request:
types: [opened, synchronize, closed, labeled]
jobs:
tf:
# Run on usual PR events and when labeled with 'tf-plan'.
if: ${{ contains(fromJSON('["opened", "synchronize", "closed"]'), github.event.action) || contains(github.event.pull_request.labels.*.name, 'tf-plan') }}
runs-on: self-hosted
permissions:
actions: read # Required to identify workflow run.
checks: write # Required to add status summary.
contents: read # Required to checkout repository.
pull-requests: write # Required to add comment and label.
env:
tool: terraform
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Terraform
if: env.tool == 'terraform'
uses: hashicorp/setup-terraform@v3
- name: Setup OpenTofu
if: env.tool == 'tofu'
uses: opentofu/setup-opentofu@v1
- name: Provision TF
uses: op5dev/tf-via-pr@v13
with:
working-directory: path/to/directory
command: ${{ github.event.pull_request.merged && 'apply' || 'plan' }}
arg-lock: ${{ github.event.pull_request.merged }}
plan-encrypt: ${{ secrets.PASSPHRASE }}
validate: true
format: true
tool: ${{ env.tool }}
- name: Remove label
if: ${{ contains(github.event.pull_request.labels.*.name, 'tf-plan') }}
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_NUMBER: ${{ github.event.number }}
run: gh api /repos/{owner}/{repo}/issues/${PR_NUMBER}/labels/tf-plan --method DELETE