-
Notifications
You must be signed in to change notification settings - Fork 3
108 lines (89 loc) · 2.89 KB
/
terraform.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
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
97
98
99
100
101
102
103
104
105
106
107
108
name: Plan and Apply Terraform
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
env:
# We don't want to create any real cloud resources from this
# repo. It is just for demonstrating guardrails evaluation on TF
# plans. So use dummy credentials that would fail if we ever tried
# to run `tf apply.
AWS_ACCESS_KEY: "asdf"
AWS_SECRET_KEY: "asdf"
GOOGLE_OAUTH_ACCESS_TOKEN: "asdf"
jobs:
terraform:
name: 'Terraform'
runs-on: ubuntu-latest
environment: production
defaults:
run:
shell: bash
strategy:
matrix:
env: ["dev", "prod"]
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Terraform
uses: hashicorp/setup-terraform@v1
- name: Terraform Init
run: terraform init
- name: Terraform Plan
run: terraform plan -state=${{ matrix.env }}.tfstate -var-file=${{ matrix.env }}.tfvars -refresh=false -out=plan.raw
- name: Convert the plan to JSON
id: planToJson
run: terraform show -json plan.raw
- name: Save JSON to a file
uses: fishcharlie/[email protected]
with:
data: ${{ steps.planToJson.outputs.stdout }}
output: plan-${{ matrix.env }}.json
- name: Upload Terraform Plan Output
uses: actions/[email protected]
with:
name: plan-file-${{ matrix.env }}
path: plan-${{ matrix.env }}.json
- name: Terraform Apply
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
run: terraform apply -auto-approve -state=${{ matrix.env }}.tfstate -var-file=dev.tfvars -input=false
resourcely-ci:
needs: terraform
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Download Terraform Plan Output
uses: actions/[email protected]
with:
name: plan-file-dev
path: tf-plan-files/
- name: Download Terraform Plan Output
uses: actions/[email protected]
with:
name: plan-file-prod
path: tf-plan-files/
- name: Save JSON to a file
uses: fishcharlie/[email protected]
with:
data: |
{
"plans": [{
"plan_file": "plan-dev.json",
"config_root_path": ".",
"environment": "dev"
},{
"plan_file": "plan-prod.json",
"config_root_path": ".",
"environment": "prod"
}]
}
output: tf-plan-files/manifest.json
- name: Resourcely CI
uses: Resourcely-Inc/resourcely-action@main
with:
resourcely_api_token: ${{ secrets.RESOURCELY_API_TOKEN }}
resourcely_api_host: "https://api.resourcely.io"
tf_plan_directory: "tf-plan-files"