-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxxx_terraform_docs.sh
executable file
·52 lines (40 loc) · 1.41 KB
/
xxx_terraform_docs.sh
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
#!/bin/bash
set -e
if ! command -v terraform-docs &> /dev/null
then
echo "!!! Plaese ensure you have terraform-docs installed & on your path !!!"
echo -e "https://github.com/terraform-docs/terraform-docs\n"
exit 42
fi
if [ "$#" -ne 1 ]; then
echo "USAGE: ./xxx_terraform-docs.sh \${YOUR_TERRAFORM_EXEC}"
echo "e.g > ./xxx_terraform-docs.sh terraform_v1.5.1"
exit 0
fi
terraform_exec=$1
### Run tf fmt
$terraform_exec fmt -recursive
unique_tf_dirs=$(find ./ -not -path "*/\.*" -not -path "*venv/*" -not -path "*node_modules/*" -iname "*.tf" -exec dirname {} \; | uniq)
for tf_dirs in $unique_tf_dirs; do
cd $tf_dirs
echo ""
pwd
# TODO: customise this further to enrich READMEs and create links to them from root directory
terraform-docs markdown table --output-file README.md --output-mode inject .
IMAGE_FILE="./images/terraform_infra.png"
if [ -f "$IMAGE_FILE" ]; then
echo "Adding infra image"
### rm previous additions
sed -i "s|images/terraform_infra.png||g" README.md
mv -f README.md README.temp
MDIMG_LINK=""
echo "$MDIMG_LINK" > README.md
echo "" >> README.md
echo "" >> README.md
cat README.temp >> README.md
rm README.temp
else
echo "nofindo"
fi
cd -
done