-
Notifications
You must be signed in to change notification settings - Fork 2
65 lines (55 loc) · 2.17 KB
/
terraform_on_pr.yml
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
name: 'PR - Deploy to Prod'
on:
workflow_dispatch:
merge_group:
pull_request:
paths-ignore:
- '*.tfstate'
- '.github/workflows/*'
permissions:
contents: write
env:
tf_version: 1.4.6
tf_working_dir: .
terrahelp_shasum: b086a87b7d98c4c84767836e897663ec7fa1ae678230a55041abdc817579a04f
jobs:
terraform:
name: 'Terraform Plan and Apply'
environment: prod
runs-on: ubuntu-latest
steps:
- uses: hashicorp/setup-terraform@v2
- uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.ref }}
- name: 'Get Terrahelp Binary'
run: wget -c https://github.com/opencredo/terrahelp/releases/download/v0.7.5/terrahelp_0.7.5_linux_amd64.tar.gz -O - | tar -xz
- name: 'Check Integrity' # Double space needed between SHA and filename
run: echo "${{ env.terrahelp_shasum }} ./terrahelp" | shasum -a256 -c-
- name: 'Decrypt State'
run: ./terrahelp decrypt --mode=full --simple-key=${{ secrets.TERRAHELP_KEY }} --nobackup --file terraform.tfstate -file=terraform.tfstate.backup
- id: init
run: terraform init
- id: validate
run: terraform validate -no-color
- id: plan
run: terraform plan -no-color --input=false
continue-on-error: false
env:
TF_VAR_cloudflare_zone_id: ${{ secrets.CF_ZONE_ID }}
TF_VAR_cloudflare_api_token: ${{ secrets.CF_API_TOKEN }}
- id: apply
run: terraform apply -no-color --input=false -auto-approve
continue-on-error: false
env:
TF_VAR_cloudflare_zone_id: ${{ secrets.CF_ZONE_ID }}
TF_VAR_cloudflare_api_token: ${{ secrets.CF_API_TOKEN }}
- name: 'Encrypt State'
run: ./terrahelp encrypt --mode=full --simple-key=${{ secrets.TERRAHELP_KEY }} --nobackup --file terraform.tfstate -file=terraform.tfstate.backup
- name: 'Commit New State'
run: |
git config --global user.name 'GitHub Actions'
git config --global user.email '[email protected]'
git add terraform.tfstate terraform.tfstate.backup
git commit -m "Add updated state"
git push origin