-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTaskfile.yaml
More file actions
95 lines (88 loc) · 3 KB
/
Taskfile.yaml
File metadata and controls
95 lines (88 loc) · 3 KB
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
version: '3'
tasks:
dashboards:
desc: Download, patch, and validate vendored dashboards from source.yaml files
cmds:
- scripts/vendor-dashboards.sh
scan:
desc: Scan for security vulnerabilities
silent: true
cmds:
- cmd: source .venv/bin/activate && checkov -d {{.CLI_ARGS | default "terraform/"}} 2>/dev/null
test:
desc: Run all tests (Terraform and Blueprint)
silent: true
cmds:
- task: test:terraform
- task: test:blueprint
test:terraform:
desc: Run Terraform tests (all or specific module)
silent: true
cmds:
- cmd: |
MODULE={{.CLI_ARGS | default "terraform"}}
if [ -d "$MODULE" ]; then
# Create a temporary directory for test results
TEMP_DIR=$(mktemp -d)
# Find all test files and run them in parallel
find "$MODULE" -type f -name '*.tftest.hcl' | while read testfile; do
testdir=$(dirname "$testfile")
(
cd "$testdir" && \
echo "Running tests in $testdir..." && \
terraform init -input=false -reconfigure && \
OUTPUT=$(terraform test -no-color 2>&1)
TEST_EXIT=$?
echo "$OUTPUT"
if [ $TEST_EXIT -ne 0 ]; then
echo "FAILED: $testfile" >> "$TEMP_DIR/failures"
fi
# Check for warnings (case-insensitive)
if echo "$OUTPUT" | grep -qi "Warning:"; then
echo "WARNINGS: $testfile" >> "$TEMP_DIR/warnings"
fi
) &
done
# Wait for all background jobs to complete
wait
# Check if any tests failed
if [ -f "$TEMP_DIR/failures" ]; then
echo "Test failures:"
cat "$TEMP_DIR/failures"
rm -rf "$TEMP_DIR"
exit 1
fi
# Check if any warnings were found
if [ -f "$TEMP_DIR/warnings" ]; then
echo "Tests completed with warnings:"
cat "$TEMP_DIR/warnings"
rm -rf "$TEMP_DIR"
exit 1
fi
rm -rf "$TEMP_DIR"
else
echo "Module path '$MODULE' does not exist."
exit 1
fi
test:blueprint:
desc: Run Windsor blueprint tests
silent: true
cmds:
- windsor test
fmt:
desc: Check Terraform formatting
silent: true
cmds:
- cmd: terraform fmt -recursive
docs:
desc: Generate Terraform documentation
silent: true
cmds:
- cmd: |
find terraform -type d -exec test -e '{}/main.tf' -a -e '{}/variables.tf' \; -print | while read -r dir; do
if [[ "$dir" == *"/modules/"* ]]; then
continue
fi
echo "Generating docs for $dir"
docker run --rm -v "$(pwd):/src" -w "/src/$dir" quay.io/terraform-docs/terraform-docs:0.20.0 markdown table --output-file README.md --output-mode inject .
done