64 lines
1.0 KiB
Bash
Executable File
64 lines
1.0 KiB
Bash
Executable File
#!/bin/bash
|
|
#
|
|
|
|
|
|
list_mods ()
|
|
{
|
|
for f in $(find modules/ -name '*.tf' ); do echo "${f%/*}"; done | sort | uniq
|
|
}
|
|
|
|
gen_mod_doc ()
|
|
{
|
|
local dir=$1
|
|
local mode=$2
|
|
local dest=${dir}/REFERENCE.md
|
|
|
|
terraform-docs --output-file "REFERENCE.md" ${mode//_/ } "$mod"
|
|
# terraform-docs ${mode//_/ } "$mod" > "$dest"
|
|
|
|
|
|
}
|
|
|
|
move_reference_in_doc_dir ()
|
|
{
|
|
local doc_dir='docs'
|
|
|
|
|
|
for file in $(find modules -name REFERENCE.md); do
|
|
new_name=${file#modules/}
|
|
new_name=${new_name%/REFERENCE.md}
|
|
new_name=${new_name//\//__}
|
|
|
|
|
|
final_name=$doc_dir/$new_name.md
|
|
final_dir=$(dirname "$final_name")
|
|
|
|
|
|
if [[ ! -d "$final_dir" ]] ; then
|
|
mkdir -p "$final_dir"
|
|
fi
|
|
mv "$file" "$final_name"
|
|
done
|
|
}
|
|
|
|
gen_docs ()
|
|
{
|
|
local modules=$(list_mods)
|
|
local fmt="yaml"
|
|
local fmt="pretty"
|
|
local fmt="markdown_document"
|
|
local fmt="markdown_table"
|
|
|
|
for mod in $modules; do
|
|
mod=${mod#./}
|
|
echo "INFO: Generate documentation for: $mod"
|
|
gen_mod_doc "$mod" "$fmt"
|
|
done
|
|
move_reference_in_doc_dir
|
|
|
|
echo "INFO: Done"
|
|
}
|
|
|
|
gen_docs
|
|
|