Skip to content

Commit d940fe6

Browse files
authored
Merge pull request #16 from PerfectThymeTech/marvinbuss/infra_baseline
Add infrastructure baseline
2 parents 5c82cb6 + f2abd6b commit d940fe6

26 files changed

+1313
-6
lines changed

.github/dependabot.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,25 @@ updates:
2323
labels:
2424
- "pip"
2525
- "dependencies"
26+
27+
# Maintain dependencies for pip
28+
- package-ecosystem: "pip"
29+
directory: "/code/backend"
30+
schedule:
31+
interval: "weekly"
32+
day: "sunday"
33+
time: "10:00"
34+
labels:
35+
- "pip"
36+
- "dependencies"
37+
38+
# Maintain dependencies for Terraform
39+
- package-ecosystem: "terraform"
40+
directory: "/code/infra"
41+
schedule:
42+
interval: "weekly"
43+
day: "sunday"
44+
time: "10:00"
45+
labels:
46+
- "terraform"
47+
- "dependencies"
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
name: Terraform Destroy Template
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
environment:
7+
required: true
8+
type: string
9+
default: "dev"
10+
description: "Specifies the environment of the deployment."
11+
config:
12+
required: true
13+
type: string
14+
description: "Specifies the configuration folder for the deployment."
15+
terraform_version:
16+
required: true
17+
type: string
18+
description: "Specifies the terraform version."
19+
node_version:
20+
required: true
21+
type: number
22+
description: "Specifies the node version."
23+
working_directory:
24+
required: true
25+
type: string
26+
description: "Specifies the working directory."
27+
tenant_id:
28+
required: true
29+
type: string
30+
description: "Specifies the tenant id of the deployment."
31+
subscription_id:
32+
required: true
33+
type: string
34+
description: "Specifies the subscription id of the deployment."
35+
secrets:
36+
CLIENT_ID:
37+
required: true
38+
description: "Specifies the client id."
39+
40+
permissions:
41+
id-token: write
42+
contents: read
43+
44+
jobs:
45+
deployment:
46+
name: Terraform Destroy
47+
runs-on: [self-hosted]
48+
continue-on-error: false
49+
environment: ${{ inputs.environment }}
50+
if: github.event_name == 'push' || github.event_name == 'release'
51+
concurrency:
52+
group: terraform-${{ inputs.config }}-${{ inputs.environment }}
53+
cancel-in-progress: false
54+
55+
env:
56+
ARM_TENANT_ID: ${{ inputs.tenant_id }}
57+
ARM_SUBSCRIPTION_ID: ${{ inputs.subscription_id }}
58+
ARM_CLIENT_ID: ${{ secrets.CLIENT_ID }}
59+
ARM_USE_OIDC: true
60+
61+
steps:
62+
# Setup Node
63+
- name: Setup Node
64+
id: node_setup
65+
uses: actions/setup-node@2028fbc5c25fe9cf00d9f06a71cc4710d4507903 # v6.0.0
66+
with:
67+
node-version: ${{ inputs.node_version }}
68+
69+
# Setup Terraform
70+
- name: Setup Terraform
71+
id: terraform_setup
72+
uses: hashicorp/setup-terraform@b9cd54a3c349d3f38e8881555d616ced269862dd # v3.1.2
73+
with:
74+
terraform_version: ${{ inputs.terraform_version }}
75+
terraform_wrapper: true
76+
77+
# Check Out Repository
78+
- name: Check Out Repository
79+
id: checkout_repository
80+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
81+
82+
# Terraform Init
83+
- name: Terraform Init
84+
working-directory: ${{ inputs.working_directory }}
85+
run: |
86+
terraform init -backend-config=../../config/${CONFIG}/azurerm.tfbackend
87+
env:
88+
CONFIG: ${{ inputs.config }}
89+
90+
# Terraform Destroy
91+
- name: Terraform Destroy
92+
working-directory: ${{ inputs.working_directory }}
93+
run: |
94+
terraform apply -var-file="../../config/${CONFIG}/vars.tfvars" -auto-approve -input=false -destroy
95+
env:
96+
CONFIG: ${{ inputs.config }}
Lines changed: 238 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,238 @@
1+
name: Terraform Template
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
environment:
7+
required: true
8+
type: string
9+
description: "Specifies the environment of the deployment."
10+
config:
11+
required: true
12+
type: string
13+
description: "Specifies the configuration folder for the deployment."
14+
terraform_version:
15+
required: true
16+
type: string
17+
description: "Specifies the terraform version."
18+
node_version:
19+
required: true
20+
type: number
21+
description: "Specifies the node version."
22+
working_directory:
23+
required: true
24+
type: string
25+
description: "Specifies the working directory."
26+
tenant_id:
27+
required: true
28+
type: string
29+
description: "Specifies the tenant id of the deployment."
30+
subscription_id:
31+
required: true
32+
type: string
33+
description: "Specifies the subscription id of the deployment."
34+
secrets:
35+
CLIENT_ID:
36+
required: true
37+
description: "Specifies the client id."
38+
39+
permissions:
40+
id-token: write
41+
contents: read
42+
pull-requests: write
43+
44+
jobs:
45+
lint:
46+
name: Terraform Lint
47+
runs-on: [ubuntu-latest]
48+
continue-on-error: false
49+
50+
steps:
51+
# Setup Terraform
52+
- name: Setup Terraform
53+
id: terraform_setup
54+
uses: hashicorp/setup-terraform@b9cd54a3c349d3f38e8881555d616ced269862dd # v3.1.2
55+
with:
56+
terraform_version: ${{ inputs.terraform_version }}
57+
terraform_wrapper: true
58+
59+
# Check Out Repository
60+
- name: Check Out Repository
61+
id: checkout_repository
62+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
63+
64+
# Terraform Format
65+
- name: Terraform Format
66+
id: terraform_format
67+
working-directory: ${{ inputs.working_directory }}
68+
run: |
69+
terraform fmt -check -recursive
70+
71+
# Add Pull Request Comment
72+
- name: Add Pull Request Comment
73+
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
74+
id: pr_comment
75+
if: github.event_name == 'pull_request'
76+
with:
77+
github-token: ${{ secrets.GITHUB_TOKEN }}
78+
script: |
79+
const output = `#### Terraform Lint Results
80+
* Terraform Version 📎\`${{ inputs.terraform_version }}\`
81+
* Working Directory 📂\`${{ inputs.working_directory }}\`
82+
* Terraform Format and Style 🖌\`${{ steps.terraform_format.outcome }}\``;
83+
84+
github.rest.issues.createComment({
85+
issue_number: context.issue.number,
86+
owner: context.repo.owner,
87+
repo: context.repo.repo,
88+
body: output
89+
})
90+
91+
plan:
92+
name: Terraform Plan
93+
runs-on: [self-hosted]
94+
continue-on-error: false
95+
environment: ${{ inputs.environment }}
96+
needs: [lint]
97+
concurrency:
98+
group: terraform-${{ inputs.config }}-${{ inputs.environment }}
99+
cancel-in-progress: false
100+
101+
env:
102+
ARM_TENANT_ID: ${{ inputs.tenant_id }}
103+
ARM_SUBSCRIPTION_ID: ${{ inputs.subscription_id }}
104+
ARM_CLIENT_ID: ${{ secrets.CLIENT_ID }}
105+
ARM_USE_OIDC: true
106+
107+
steps:
108+
# Setup Node
109+
- name: Setup Node
110+
id: node_setup
111+
uses: actions/setup-node@2028fbc5c25fe9cf00d9f06a71cc4710d4507903 # v6.0.0
112+
with:
113+
node-version: ${{ inputs.node_version }}
114+
115+
# Setup Terraform
116+
- name: Setup Terraform
117+
id: terraform_setup
118+
uses: hashicorp/setup-terraform@b9cd54a3c349d3f38e8881555d616ced269862dd # v3.1.2
119+
with:
120+
terraform_version: ${{ inputs.terraform_version }}
121+
terraform_wrapper: true
122+
123+
# Check Out Repository
124+
- name: Check Out Repository
125+
id: checkout_repository
126+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
127+
128+
# Terraform Init
129+
- name: Terraform Init
130+
id: terraform_init
131+
working-directory: ${{ inputs.working_directory }}
132+
run: |
133+
terraform init -backend-config=../../config/${CONFIG}/azurerm.tfbackend
134+
env:
135+
CONFIG: ${{ inputs.config }}
136+
137+
# Terraform Validate
138+
- name: Terraform Validate
139+
id: terraform_validate
140+
working-directory: ${{ inputs.working_directory }}
141+
run: |
142+
terraform validate
143+
144+
# Terraform Plan
145+
- name: Terraform Plan
146+
id: terraform_plan
147+
working-directory: ${{ inputs.working_directory }}
148+
run: |
149+
terraform plan -var-file="../../config/${CONFIG}/vars.tfvars" -input=false
150+
env:
151+
CONFIG: ${{ inputs.config }}
152+
153+
# Add Pull Request Comment
154+
- name: Add Pull Request Comment
155+
id: pr_comment
156+
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
157+
if: github.event_name == 'pull_request'
158+
continue-on-error: true
159+
env:
160+
PLAN: "terraform\n${{ steps.terraform_plan.outputs.stdout }}"
161+
with:
162+
github-token: ${{ secrets.GITHUB_TOKEN }}
163+
script: |
164+
const output = `#### Terraform Validation & Plan Results
165+
* Terraform Version 📎\`${{ inputs.terraform_version }}\`
166+
* Working Directory 📂\`${{ inputs.working_directory }}\`
167+
* Terraform Initialization ⚙️\`${{ steps.terraform_init.outcome }}\`
168+
* Terraform Validation 🤖\`${{ steps.terraform_validate.outcome }}\`
169+
* Terraform Plan 📖\`${{ steps.terraform_plan.outcome }}\`
170+
171+
<details><summary>Show Plan</summary>
172+
173+
\`\`\`\n
174+
${process.env.PLAN}
175+
\`\`\`
176+
177+
</details>`;
178+
179+
github.rest.issues.createComment({
180+
issue_number: context.issue.number,
181+
owner: context.repo.owner,
182+
repo: context.repo.repo,
183+
body: output
184+
})
185+
186+
apply:
187+
name: Terraform Apply
188+
runs-on: [self-hosted]
189+
continue-on-error: false
190+
environment: ${{ inputs.environment }}
191+
# if: github.event_name == 'push' || github.event_name == 'release'
192+
needs: [plan]
193+
concurrency:
194+
group: terraform-${{ inputs.config }}-${{ inputs.environment }}
195+
cancel-in-progress: false
196+
197+
env:
198+
ARM_TENANT_ID: ${{ inputs.tenant_id }}
199+
ARM_SUBSCRIPTION_ID: ${{ inputs.subscription_id }}
200+
ARM_CLIENT_ID: ${{ secrets.CLIENT_ID }}
201+
ARM_USE_OIDC: true
202+
203+
steps:
204+
# Setup Node
205+
- name: Setup Node
206+
id: node_setup
207+
uses: actions/setup-node@2028fbc5c25fe9cf00d9f06a71cc4710d4507903 # v6.0.0
208+
with:
209+
node-version: ${{ inputs.node_version }}
210+
211+
# Setup Terraform
212+
- name: Setup Terraform
213+
id: terraform_setup
214+
uses: hashicorp/setup-terraform@b9cd54a3c349d3f38e8881555d616ced269862dd # v3.1.2
215+
with:
216+
terraform_version: ${{ inputs.terraform_version }}
217+
terraform_wrapper: true
218+
219+
# Check Out Repository
220+
- name: Check Out Repository
221+
id: checkout_repository
222+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
223+
224+
# Terraform Init
225+
- name: Terraform Init
226+
working-directory: ${{ inputs.working_directory }}
227+
run: |
228+
terraform init -backend-config=../../config/${CONFIG}/azurerm.tfbackend
229+
env:
230+
CONFIG: ${{ inputs.config }}
231+
232+
# Terraform Apply
233+
- name: Terraform Apply
234+
working-directory: ${{ inputs.working_directory }}
235+
run: |
236+
terraform apply -var-file="../../config/${CONFIG}/vars.tfvars" -auto-approve -input=false
237+
env:
238+
CONFIG: ${{ inputs.config }}

0 commit comments

Comments
 (0)