forked from coralogix/terraform-coralogix-aws
-
Notifications
You must be signed in to change notification settings - Fork 1
129 lines (116 loc) · 4.43 KB
/
test.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
name: Terraform testing
on:
pull_request:
types: [opened, synchronize]
branches: [master]
paths:
- "modules/**"
jobs:
check:
name: Check
runs-on: ubuntu-latest
outputs:
packages: ${{ env.packages }}
steps:
- name: Checkout
uses: actions/checkout@v3
with:
persist-credentials: false
fetch-depth: 0
- name: Get changed packages
id: get-changed-packages
run: |
export PACKAGES=$(git diff --name-only --diff-filter=d ${{ github.event.pull_request.base.sha || 'origin/master' }} ${{ github.sha }} modules/ | xargs -n1 dirname | sed -r 's/modules\/([^\/]+).*$/modules\/\1/g' | xargs -n1 basename | sort | uniq | jq -rcnR '[inputs]')
echo "packages=$PACKAGES" >> $GITHUB_ENV
validate:
name: Validate
runs-on: ubuntu-latest
needs: check
strategy:
fail-fast: false
matrix:
package: ${{ fromJSON(needs.check.outputs.packages) }}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Check for missing test directories
run: |
chmod +x tests/compare_directories_test.sh
output=$(tests/compare_directories_test.sh)
# Check if the output is empty
if [ -z "$output" ] || [[ "$output" == "locals_variables" ]] ; then
echo "[INFO] No tests are missing for Terraform module ${{ matrix.package }}."
else
echo "$output"
exit 1
fi
- name: Compare variables in test file and in the module
run: |
if [[ ${{ matrix.package }} != "locals_variables" ]]; then
chmod +x tests/test_variables_script.sh
output=$(tests/test_variables_script.sh modules/${{ matrix.package }}/variables.tf tests/${{ matrix.package }}/${{ matrix.package }}.tf)
# Check if the output is empty
if [ -z "$output" ]; then
echo "[INFO] Test file for module ${{ matrix.package }} is currect."
else
echo "[ERROR] This variables are missing in the module test file: $output"
exit 1
fi
fi
- name: Configure AWS credentials
env:
AWS_ACCESS_KEY_ID: ${{ secrets.TESTING_ACCESS_KEY }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.TESTING_SECRET_ACCESS_KEY }}
run: |
echo "AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID}" >> $GITHUB_ENV
echo "AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY}" >> $GITHUB_ENV
# - name: Terraform init
# run: |
# if [[ ${{ matrix.package }} != "locals_variables" ]];then
# cd "tests/${{ matrix.package }}"
# terraform init
# fi
# - name: Terraform validate
# run: |
# if [[ ${{ matrix.package }} != "locals_variables" ]];then
# cd "tests/${{ matrix.package }}"
# terraform validate
# fi
# - name: Terraform plan
# run: |
# if [[ ${{ matrix.package }} != "locals_variables" ]];then
# cd "tests/${{ matrix.package }}"
# terraform plan
# fi
- name: send log to log group
run: |
aws logs put-log-events \
--log-group-name "gr-test" \
--log-stream-name "test2" \
--log-events "[{\"timestamp\": $(date +%s)000, \"message\": \"This is a log message sent to CloudWatch.\"}]"
# - name: Terraform apply
# continue-on-error: true
# run: |
# if [[ ${{ matrix.package }} != "locals_variables" ]];then
# cd "tests/${{ matrix.package }}"
# terraform apply -auto-approve
# fi
# - name: Terraform apply in case of an error
# run: |
# if [[ ${{ matrix.package }} != "locals_variables" ]];then
# cd "tests/${{ matrix.package }}"
# terraform apply -auto-approve
# fi
# - name: Terraform destroy
# continue-on-error: true
# run: |
# if [[ ${{ matrix.package }} != "locals_variables" ]];then
# cd "tests/${{ matrix.package }}"
# terraform destroy -auto-approve
# fi
# - name: Terraform destroy in case of an error
# run: |
# if [[ ${{ matrix.package }} != "locals_variables" ]];then
# cd "tests/${{ matrix.package }}"
# terraform destroy -auto-approve
# fi