forked from mischavandenburg/kubecraft
-
Notifications
You must be signed in to change notification settings - Fork 0
141 lines (110 loc) · 3.46 KB
/
terraform-pipeline.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
name: Terraform pipeline
on:
workflow_dispatch:
push:
paths:
- 'terraform/**'
branches:
- main
permissions:
id-token: write
contents: read
env:
ARM_ACCESS_KEY: ${{ secrets.ARM_ACCESS_KEY }}
ARM_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
ARM_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
ARM_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
jobs:
plan:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./terraform
name: Plan
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Azure login
uses: azure/login@v2
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
- name: Setup terraform
uses: hashicorp/setup-terraform@v3
- name: Terraform format check
continue-on-error: true
id: fmt
run: terraform fmt -check
- name: Terraform init
id: init
run: terraform init
- name: Terraform validate
id: validate
run: terraform validate -no-color
- name: Terraform plan
id: plan
run: terraform plan -no-color -out terraform-plan
- uses: WcAServices/markdown-template-action@v1
continue-on-error: true
with:
# These will be injected into the below template, in addition to GitHub's standard
# variables. You can perform string operations here as well.
variables: >-
FMT_OUTCOME="${{ steps.fmt.outcome }}"
INIT_OUTCOME="${{ steps.init.outcome }}"
VALIDATE_OUTCOME="${{ steps.validate.outcome }}"
VALIDATE_OUTPUT="${{ steps.validate.outputs.stdout }}"
PLAN_OUTCOME="${{ steps.plan.outcome }}"
PLAN_OUTPUT="${{ steps.plan.outputs.stdout }}"
template: |
#### Terraform Format and Style 🖌`$FMT_OUTCOME`
#### Terraform Initialization ⚙️`$INIT_OUTCOME`
#### Terraform Validation 🤖`$VALIDATE_OUTCOME`
<details>
<summary>Validation Output</summary>
```
$VALIDATE_OUTPUT
```
</details>
#### Terraform Plan 📖`$PLAN_OUTCOME`
<details>
<summary>Show Plan</summary>
```terraform
$PLAN_OUTPUT
```
</details>
*Actor: @$GITHUB_ACTOR, Action: `$GITHUB_EVENT_NAME`*
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: plan
path: ./terraform
apply:
runs-on: ubuntu-latest
environment: staging
needs: plan
name: Apply
defaults:
run:
working-directory: ./terraform
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Azure login
uses: azure/login@v2
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
- name: Setup terraform
uses: hashicorp/setup-terraform@v3
- name: Terraform init
run: terraform init
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: plan
path: ./terraform
- name: Terraform apply
run: terraform apply -auto-approve terraform-plan