-
Notifications
You must be signed in to change notification settings - Fork 17
96 lines (84 loc) · 2.38 KB
/
Copy pathplan-on-pr.yml
File metadata and controls
96 lines (84 loc) · 2.38 KB
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
name: Plan or Apply
on:
pull_request:
branches:
- main
# paths:
# - 'terraform/**'
push:
branches:
- main
paths:
- 'terraform/**'
jobs:
lint:
name: Lint
runs-on: ubuntu-20.04
steps:
- name: Check out code
uses: actions/checkout@v2
- name: Setup Terraform
uses: hashicorp/setup-terraform@v1
with:
terraform_version: 1.0.9
- name: Run terraform fmt check
run: terraform fmt -check -diff -recursive ./terraform
plan_or_apply:
name: Plan
env:
TF_VAR_allowed_account_id: ${{ secrets.ALLOWED_ACCOUNT_ID }}
runs-on: ubuntu-20.04
strategy:
fail-fast: false
matrix:
path:
- dev
- stage
- prod
steps:
- name: Check out code
uses: actions/checkout@v2
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-region: us-east-1
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
- name: Setup Terraform
uses: hashicorp/setup-terraform@v1
with:
terraform_version: 1.0.9
- name: Initialize Terraform
run: |
cd terraform/${{ matrix.path }}
terraform init -input=false
- name: Plan Terraform
id: plan
continue-on-error: true
run: |
cd terraform/${{ matrix.path }}
terraform plan -no-color -out plan.tfplan
- name: Apply Terraform
id: apply
continue-on-error: true
if: |
steps.plan.outcome == 'success'
&& github.ref == 'refs/heads/main'
&& github.event_name == 'push'
run: |
cd terraform/${{ matrix.path }}
terraform apply \
-input=false \
-no-color \
plan.tfplan
- name: Post Plan/Apply to GitHub PR
uses: mshick/add-pr-comment@v1
with:
allow-repeats: true
repo-token: ${{ secrets.GITHUB_TOKEN }}
repo-token-user-login: 'github-actions[bot]'
message: |
## ${{ matrix.path }} plan${{ github.ref == 'refs/heads/main' && github.event_name == 'push' && '/apply' }}
```
${{ join(steps.plan.outputs.*) }}${{ join(steps.apply.outputs.*) }}
```