-
Notifications
You must be signed in to change notification settings - Fork 20
72 lines (59 loc) · 1.79 KB
/
terraform-validate.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
name: Terraform Validate
run-name: ${{ github.actor }} - ${{ github.ref_name }}
on:
pull_request:
branches: ["main"]
workflow_dispatch:
jobs:
terraform_validate:
name: "Format and Validate Code"
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Terraform
uses: hashicorp/setup-terraform@v3
with:
terraform_version: 1.8.4
- name: Check count meta-argument
run: |
if grep -q 'count *= *' ./*.tf; then
echo "count meta-argument is present."
else
echo "count meta-argument not found!"
exit 1
fi
- name: Check for_each meta-argument
run: |
if ! grep -q 'for_each =' ./*.tf; then
echo "for_each meta-argument not found!"
exit 1
fi
echo "for_each meta-argument is present."
- name: Check lifecycle block
run: |
if ! grep -q 'lifecycle {' ./*.tf; then
echo "lifecycle block not found!"
exit 1
fi
echo "lifecycle block is present."
- name: Check dynamic blocks
run: |
if ! grep -q 'dynamic "security_rule"' ./*.tf; then
echo "dynamic blocks for network security rules not found!"
exit 1
fi
echo "dynamic blocks are present."
- name: Check built-in functions usage
run: |
if ! grep -q 'upper(' ./*.tf || ! grep -q 'join(' ./*.tf || ! grep -q '\[for' ./*.tf; then
echo "built-in functions not used correctly!"
exit 1
fi
echo "built-in functions are present."
- name: Terraform Fmt
run: terraform fmt -check -recursive -diff
- name: Terraform Init
run: terraform init
- name: Terraform Validate
run: terraform validate